| By Hovhannes Avoyan | Article Rating: |
|
| January 24, 2012 03:30 AM EST | Reads: |
397 |

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 397
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 Monitis, Inc., a provider of on-demand systems management and monitoring software to 50,000 users spanning small businesses and Fortune 500 companies.
Prior to Monitis, he served as General Manager and Director of Development at prominent web portal Lycos Europe, where he grew the Lycos Armenia group from 30 people to over 200, making it the company's largest development center. Prior to Lycos, Avoyan was VP of Technology at Brience, Inc. (based in San Francisco and acquired by Syniverse), which delivered mobile internet content solutions to companies like Cisco, Ingram Micro, Washington Mutual, Wyndham Hotels , T-Mobile , and CNN. Prior to that, he served as the founder and CEO of CEDIT ltd., which was acquired by Brience. A 24 year veteran of the software industry, he also runs Sourcio cjsc, an IT consulting company and startup incubator specializing in web 2.0 products and open-source technologies.
Hovhannes is a senior lecturer at the American Univeristy of Armenia and has been a visiting lecturer at San Francisco State University. He is a graduate of Bertelsmann University.
- SharePoint 2010 Development with Silverlight Book Review
- How MRP and Production Planning and Scheduling Software Differ
- Book Review: Decision Management Systems
- Planning, Scoping and Recon Techniques
- XML Security Gateway plugging holes for Public Clouds
- Learn Open Source Database Tools from Stanford for Free
- Software Architecture: A Comprehensive Framework and Guide for Practitioners Book Review
- WGU Washington Doubles Enrollment in First Six Months
- Microsoft Lightswitch Training in Bengaluru
- MuleSoft Delivers Record 2011 Results
- Hadoop Quickstart: Use Whirr to automate standup of your distributed cluster on Rackspace
- Using Tomcat With a Database – Performance Optimization Tips
- Service Design Patterns: Fundamental Design Solutions for SOAP/WSDL
- SharePoint 2010 Development with Silverlight Book Review
- The New ROI: A Return on Innovation, and Using Data to Do It
- Reading an Attribute from an LDAP Directory
- How MRP and Production Planning and Scheduling Software Differ
- Book Review: Decision Management Systems
- Planning, Scoping and Recon Techniques
- Bluegiga Enables the Development of Bluetooth® 4.0 Accessories for iPhone 4S
- XML Security Gateway plugging holes for Public Clouds
- Learn Open Source Database Tools from Stanford for Free
- Bluegiga facilite le développement d'accessoires Bluetooth® 4.0 pour iPhone 4S
- Bluegiga ermöglicht die Entwicklung von Bluetooth® 4.0 Zubehör für das iPhone 4S
- Where Are RIA Technologies Headed in 2008?
- Processing XML with C# and .NET
- AJAX World RIA Conference & Expo Kicks Off in New York City
- JSON vs XML - A Jason vs Freddie Sequel
- Has the Technology Bounceback Begun?
- i-Technology Viewpoint: The Very Confused World of 3D and XML
- BPEL Processes and Human Workflow
- The Top 250 Players in the Cloud Computing Ecosystem
- The Top 250 Players in the Cloud Computing Ecosystem
- Generating XML from Relational Database Tables
- Open Source Database Special Feature: An Introduction to Berkeley DB XML
- "HP's Problem Ain't the SAP Install," Says Sun's Schwartz




















