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

> From: [EMAIL PROTECTED]
> To: users@tomcat.apache.org
> Subject: Re: Tomcat 5.5, JNDI Connection Pooling, Active connections keep 
> increasing....
> Date: Tue, 16 Sep 2008 18:58:25 +0200
> 
> 
> ----- Original Message ----- 
> From: "Johnny Kewl" <[EMAIL PROTECTED]>
> To: "Tomcat Users List" <users@tomcat.apache.org>
> Sent: Tuesday, September 16, 2008 5:41 PM
> Subject: Re: Tomcat 5.5, JNDI Connection Pooling, Active connections keep 
> increasing....
> 
> 
> >
> > ----- Original Message ----- 
> > From: "Brantley Hobbs" <[EMAIL PROTECTED]>
> > To: "Tomcat Users List" <users@tomcat.apache.org>
> > Sent: Tuesday, September 16, 2008 5:27 PM
> > Subject: Re: Tomcat 5.5, JNDI Connection Pooling, Active connections keep 
> > increasing....
> >
> >
> >> "return" statements do not prevent the finally block from executing:
> >>
> >> http://java.sun.com/docs/books/tutorial/essential/exceptions/finally.html
> >
> > I stand corrected...
> > Always understood as "during exception handling"... but you right it seems
> >
> > I just cant bring myself to write code like that... feels un-natural...
> >
> > I would still put return after the close... apologies...
> 
> 
> Ok sinoea, what I thought was just s little slip turns out to be right... I 
> actually tested it... that finally does run as the method loses scope... I 
> actually wonder how they do that... I imagine a destructor in a C class 
> underneath Java... its interesting, but I got to tell you, you doing the all 
> the good text bokk stuff, but the code makes me feel uncomfortable... mmmm
> 
> Anyway... I think you got a threading problem...
> You using static class and servlets are multithreaded....
> 
> Rather do something like this...
> 
> Collection<Branch> branches =  new 
> BranchData().loadBranches(Data.getDataSource(), 1);
> 
> and get rid of the static methods in that BranchData class....
> 
> ie make it thread safe... at the moment you have multiple threads in that 
> static method... and with that finally I really dont know... haha
> 
> and then...
> 
>  results.close();
>  statement.close();
>  connection.close();
>  return branches;
> 
> Would make me happy... and handle those exceptions
> 
>                 } catch (SQLException e) {
>                     branch.setErrorMsg("Dear User, you have run out of 
> connections");
>                 }finally{
>                     //absolute critical stuff
>                 }
> 
> 
> But that really is just a style thing from the looks of things... although I 
> do think that with just a finally, you will still get a ungly servlet 
> exception...
> ie you are definitely cleaning up... but you not telling the user why... its 
> style
> 
> You doing all the good stuff... but more important even if you forget a 
> final or two... is just a nice clean readable flow... I think ;)
> 
> We have a style clash.... ;)
> 
> Anyway thing your problem may go away once its thread safe ;)
> 
> Thanks... learnt something ;)
> Will keep guessing till we get it ;)
> ---------------------------------------------------------------------------
> 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]
> 

_________________________________________________________________
Make a mini you and download it into Windows Live Messenger
http://clk.atdmt.com/UKM/go/111354029/direct/01/

Reply via email to