
By Hovhannes Avoyan | Article Rating: |
|
January 24, 2012 03:30 AM EST | Reads: |
2,569 |
The Internet is a great resource, but it is sometimes too much to wade through hundreds of web pages looking for tips about using Tomcat with a database. So we at Monitis have done it for you! Below are some of the more useful tips found in various places on the Internet.
Tip #1 – Don’t Ignore Database Performance
Webapps typically use databases. So, you have to tune the webapp along with the database if you want optimal performance. Take our advice. Performance test the database and define an appropriate database connection pool (maxActive, maxIdle, and maxWait in the Resource element).
Tip #2 – Determine the Cause of Database Connection Timeouts
Simply increasing maxWait in the resource element may not be the best way to deal with database connection timeouts. The timeouts may be the result of garbage collection.
Garbage collection requires that all running processes in the Java virtual machine be temporarily suspended. If garbage collection takes too long, the database connections will time out. The timeout here is not because of some problem in the application. It is simply because garbage collection is taking too long.
The more frequently garbage is collected, the less garbage there will be to collect each time. Configure garbage collection so it does not take more than one second.
Tip #3 – Share Database Connections
If every application opens and closes its own database connections, all applications run slower. Instead, if applications share connections by returning them to a common pool rather than closing them, all applications run faster.
Tomcat can be configured for this type of connection pooling. Simply set maxActive and maxIdle to appropriate values in the resource element.
Tip #4 – Return Database Connections to the Pool Properly
Do not close database connections twice. When using connection pooling, the first time you close you return the connection to the pool, and the second time you close, you could inadvertently close the connection after another application has started using it. If you are experiencing “Connection Closed” exceptions, this may be the cause. So, don’t do that!
Tip #5 – Configure Your Database as a Global Naming Resource or For a Single Context
Identify the Java Database Connectivity (JDBC) database in a resource element in the context.xml file if you want the resource to be available to one application only. Identify the JDBC resource in a resource element in the server.xml file if you want the resource to be available to all applications.
If multiple applications need access to a database, the database resource can be created globally in the server.xml file or each application can create its own resource in its own context.xml file. You need to decide which is best.
Making databases available to one application only (in context.xml) creates the resource when the application starts. Making databases available globally (in server.xml) creates the resource when the server starts, which means restarting the server every time you make changes to the resource configuration.
Configuring the database resource in the context.xml file once for each application is recommended because it makes the application more portable.
If different applications have different access levels and those access levels are determined by the database user id, then the database resource must be configured in each application’s context.xml file.
Tip #6 – Do Not Use the JDBC-ODBC Bridge
The JDBC-ODBC (Open Database Connectivity) Bridge bundled with Tomcat’s Java Development Kit (JDK) was never intended for a production environment. Use a third-party driver instead.
Using Tomcat with a database is easy. All you have to know are some good tips to keep your database performing trouble-free. Monitis is happy to provide you with this knowledge and advice. Read more about Tomcat here!
More about Apache Tomcat performance optimization tips here.
Share Now:










Read the original blog entry...
Published January 24, 2012 Reads 2,569
Copyright © 2012 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Hovhannes Avoyan
Hovhannes Avoyan is the CEO of PicsArt, Inc.,
![]() Jun. 20, 2017 06:00 PM EDT Reads: 261 |
By Elizabeth White ![]() Jun. 20, 2017 04:45 PM EDT Reads: 944 |
By Yeshim Deniz ![]() Jun. 20, 2017 02:15 PM EDT Reads: 1,310 |
By Elizabeth White ![]() Jun. 20, 2017 12:00 PM EDT Reads: 973 |
By Elizabeth White ![]() Jun. 20, 2017 12:00 PM EDT Reads: 864 |
By Liz McMillan ![]() Jun. 20, 2017 08:30 AM EDT Reads: 1,019 |
By Yeshim Deniz ![]() Jun. 20, 2017 07:45 AM EDT Reads: 1,349 |
By Yeshim Deniz ![]() Jun. 20, 2017 07:30 AM EDT Reads: 1,440 |
By Yeshim Deniz ![]() Jun. 20, 2017 07:15 AM EDT Reads: 1,413 |
By Elizabeth White ![]() Jun. 20, 2017 04:15 AM EDT Reads: 1,347 |
By Yeshim Deniz ![]() Jun. 19, 2017 04:15 PM EDT Reads: 2,032 |
By Yeshim Deniz ![]() Jun. 19, 2017 10:00 AM EDT Reads: 2,218 |
By Elizabeth White ![]() Jun. 11, 2017 04:00 PM EDT Reads: 1,516 |
By Liz McMillan ![]() Jun. 11, 2017 04:00 PM EDT Reads: 1,380 |
By Yeshim Deniz ![]() Jun. 10, 2017 06:45 AM EDT Reads: 1,912 |
By Elizabeth White ![]() Jun. 8, 2017 12:00 PM EDT Reads: 1,556 |
By Liz McMillan ![]() Jun. 8, 2017 09:00 AM EDT Reads: 1,540 |
By Liz McMillan ![]() Jun. 8, 2017 07:00 AM EDT Reads: 2,388 |
By Yeshim Deniz ![]() Jun. 8, 2017 12:00 AM EDT Reads: 6,017 |
By Carmen Gonzalez ![]() Jun. 7, 2017 08:00 PM EDT Reads: 6,729 |