Solved

connection ooling with tomcat

Posted on 2004-08-19
7
163 Views
Last Modified: 2013-11-24
Hi,  I understand that to get connection pooling to work with tomcat I need to modify some configuration files.

I have docs on how to do that , so thats fine.

My question is to do with whether the methods used to call the getConnection object should be synchronized or not.

Currently the getConnection method is called using synchronized methods. so that only one method can be dealing with it at one time.

Am i correct in htinking, once connection pooling is enabled, the methods which call cetConnection need not be synchronized?

The second part iof my question is what will happen if say, I have configured 15 connections to be in the pool and there comes a time when 16 are needed?  will the last method to request a connection just have to wait its turn?

If so, how will i be able to test if it is working?
0
Comment
Question by:rosshind
  • 5
  • 2
7 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 11843673
Hi rosshind,

> Am i correct in htinking, once connection pooling is enabled, the
> methods which call cetConnection need not be synchronized?


I would keep the getConnection method synchronized.

> The second part iof my question is what will happen if say, I have
> configured 15 connections to be in the pool and there comes a time when
> 16 are needed?  will the last method to request a connection just have
> to wait its turn?

It depends on the algorithm used with the conneciton pool. Many servers woudl just wait for a connection to be available before proceeding, others would just create a new connection after the limit is reached.

Regards
0
 
LVL 35

Accepted Solution

by:
girionis earned 500 total points
ID: 11843696
> > Am i correct in htinking, once connection pooling is enabled, the
> > methods which call cetConnection need not be synchronized?
> >

> I would keep the getConnection method synchronized.

I mean, if you call getConnection this should not be synchronized, but the implementation getConnection() of the pool is probably synchronized.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11843713
> If so, how will i be able to test if it is working?

Just have a for loop that creates 16 connections, perform some long data processing and see the time it takes for each one.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:rosshind
ID: 11843907
I have a load of DAO methods which currently are synchronized,

what I'll do is remove synchronization form them,  and make the static method which wraps the getConnection method synchronized.

Is that what you would suggest?
0
 
LVL 35

Expert Comment

by:girionis
ID: 11844073
I think you could avoid synchronizing the call to getConnection since the container's implementation of the connection pool should be already synchronized. Maybe you want to take a look here to see how a conneciton pool is implemented: http://www.webdevelopersjournal.com/columns/connection_pool.html
0
 

Author Comment

by:rosshind
ID: 11851368
Thanks a million,

thats a real help,  I have it all working now.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11851524
Thak you for accepting, glad I was of help :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question