Java Database Performance Best practices

Source: Internet
Author: User

Java Database performance Best Practices


  • Spend time evaluating the bestJDBC driverfor the application.
  • The best driver would often vary depending on the specific deploy ment. The same application is better with one JDBC driver in one deployment and a different JDBC driver in a differ ENT deployment.
  • If There is a choice,avoid ODBC and type 1 JDBC Dr Ivers.
  • Java applications would typically execute the same SQL statement repeatedly. In those cases, reusing prepared statements would offer a significant performance boost.
  • Prepared Statementsmust is pooled on a per-connection basis.
Most JDBC drivers and Java EE frameworks can does this automatically.
    • Prepared statements can consume a significant amount of heap.
The size of the statement pool must is carefully tuned to pre vent GC issues from pooling too many very large objects.


  • actions is expensive to commit, and the locking associated with  transactions can prevent database scaling.
  • transaction increases the amount of time that locks associated  with the transaction is held. Especially for transactions using  stricter semantics, the balance should be toward committing  more frequently rather than holding the locks longer.
  • for fine-grained control of transactions in JDBC, use a default transaction_read_uncommitted level and explicit ly lock data as needed.

    • applications that process large amounts of data from a query should consider changing thefetch size of the data.
    • there is a trade-off between loading too much data in the Appli cation (putting pressure on the garbage collector) and making frequent database calls to retrieve a set of data.

I ' ve recommended using the setfetchsize () method here on the (prepared) statement
object, but this method also exists on the ResultSet interface. In either case, the size is
just a hint. The JDBC driver is free to ignore this value, or round it to some other value,
or anything else it wants to do. There is no assurances either it, but setting the value
before the query is executed was more likely to result in the Hint being honored.
Some JDBC Drivers also allow you to set a default fetch size when the connection are
created by passing a property t o the Getconnection () method of the DriverManager.
Consult Your vendor ' s documentation if that path seems easier to manage.


Reading notes:

Java Performance:the Definitive Guide
by Scott Oaks
Copyright? Scott Oaks. All rights reserved.
Printed in the states of America.

Java Database Performance Best practices

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.