advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Tutorials : Building Web Applications Using Servlets and JSP :

With every user trying to log in, our login Servlet will issue a call to this validateUser method. Every call to validateUser method will result in establishing a separate connection with the database. This is definitely not the best approach. A few problems with this approach:

  1. Every user trying to log in 'waits' for a connection to be established with the database.
  2. There is an overhead with opening and closing the connection with every request.
  3. We are not checking conditions such as 'if the no. of allowed connections is over'. Such a condition will result into our validateUser method not getting a valid connection.

These types of problems are easily solved with the use of a connection pool. The basic idea of a connection pool is:

  • It is a 'collection' of open 'connections' with the database.
  • The connectionPool object when instantiated will open a predefined no. of connections (say 10 ) with the database.
  • It will have methods like getConnection that will return a reference to one of these 'already established' connections.
  • Similarly a returnConnection method will return the connection back to the pool.
  • A Servlet will instantiate this connectionPool in its 'init' method. Note that the init method is executed only once - when the servlet is loaded.
  • The doPost and other methods will call the getConnection method, use this connection to send and receive data (SQL and result) over this connection.
  • The connectionPool will keep track of returned and 'in use' connections.

This type of a connection pool will solve a lot of our performance problems but there are still a few more things to be considered:

  1. The Servlet by its very nature is executed in a multithreaded environment. The use of such a connection pool should be made 'thread safe', (One simple way is to 'synchronize' the getConnection method).
  2. We will need to consider conditions such as 'stale connections'.

This serves as one of the basic needs to use an application server. Imagine an application server that will take care of all of these issues discussed! More over it can support a connection pool over the whole application and not just one Servlet.

There are some other features common with many application servers, such as:

  1. Transaction Management: Distributed transaction management support.
  2. Connection Pooling: Handling database connections.
  3. Fault Tolerance: No single point of failure.
  4. Load Balancing: Ability to balance load with multiple servers.
  5. EJB Support (component management): - Support for J2EE - EJB standard.

The bottom line is: a good application server will 'shield' the application programmer from many of these technical issues. Click here to Explore the World of Application Servers.

Commonly used application servers are:

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs