----- Original Message -----
From: "sinoea kaabi" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <users@tomcat.apache.org>
Sent: Wednesday, September 17, 2008 11:31 AM
Subject: RE: Tomcat 5.5, JNDI Connection Pooling, Active connections keep
increasing....
Thanks,
First I will try to close resources before returning.
Although I am sure that the finally blocks are reached, since I use logging
in the last finally block and the log is
outputted.
try {
} finally {
connection.close();
Data.logConnection(connection); // this is logged
}
But I'll give it a try anyway.
Object object = null;
try {
} finally {
close resources..
}
return object;
The static methods are not thread-safe you say!
So, what exactly does it mean when we say that Tomcat is thread safe for
requests.
Tomcat creates a new thread for each request, so somehow my static methods
are then thread safe (incdirectly, since it is managed by Tomcat).
Request A > new Thread A > using my static method for loadBranches(...)
Request B > new Thread B > using my static method for loadBranches(...)
Thread B must wait until Thread A is done.
Since threads are managed by tomcat, no thread should be able to use a
static method that is used by another thread.
Or in fact, you must be right, should I declare them synchronized?
public static synchronized loadBranches(...)
Thanks,
Sinoea
=====================================
Yes your finally blocks are working.... I checked that... the book is right
;)
On threading..... No.... just make the class *non* static....
Collection<Branch> branches = *NEW*
BranchData().loadBranches(Data.getDataSource(), 1);
so now each thread has its own class.....
I imagine thats tomcats pool is already thread safe...
synchronized will work... but its a bottle neck... it will make tomcat Q...
and there is a setting in tomcat somewhere where one can make it single
threaded... but again it will slow it down... you only use that when a coder
has cocked up ;)
In threading the thing to watch is those global variables... so without
seeing your actual code its difficult to spot problems...
Thread safety is more of an art than a science...
New should do it because every thread is getting its own class... so a class
is isolated, the connection and everything else is inside it... and they
cant mess with each other... in theory... if there are no shared globals...
So I think whats happening in your static class is something like this...
Thread 1 opens connection 1.... inside class
Thread 2 open connection 2.... also inside class
Close connection 2
Close connection 2
ie same connection is no closed twice and connection 1 slips out... that
wont happen if the class in not static...
.... I think ;)
have fun...
---------------------------------------------------------------------------
HARBOR : http://www.kewlstuff.co.za/index.htm
The most powerful application server on earth.
The only real POJO Application Server.
See it in Action : http://www.kewlstuff.co.za/cd_tut_swf/whatisejb1.htm
---------------------------------------------------------------------------
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]