> From: Stefan Riegel [mailto:stefan.rie...@telig.de] > Subject: Re: Random Connection Closed Exceptions - Question > to the code example > > Yes, I find the solution somewhat ugly and not very intuitive.
Which solution are you referring to? If it's the one in the Tomcat docs, that so far still seems the simplest and most obvious to me. What's not shown in the example is any additional processing that might be done after going through the result set; if that processing is extensive, it's good to close the various DB-related objects as early as possible to make the connection available to other requests. Likewise, nulling out variables allows GC to reclaim the object space as early as possible. This should be standard practice in any server-related programming: minimize resource usage. (This is also why you should close a ResultSet as early as possible, rather than waiting for some later action to do so indirectly.) > - Request 1 running in Thread 1 gets a db connection. > - Request 1 closes the db connection. > - The JVM switches the running thread to Thread 2 > - Request 2 running in Thread 2 gets a db connection (the same db > connection just closed by Request 1). > - The JVM switches the running thread back to Thread 1 > - Request 1 closes the db connection a second time in a finally block. > - The JVM switches the running thread back to Thread 2 > - Request 2 Thread 2 tries to use the db connection but fails because > Request 1 closed it. Looks like the above was written in the bad old days of what was called "green threads", where all Java threads were actually run by a single native thread. The "green threads" concept thankfully went the way of the dodo quite a few years ago, and there is now a one-to-one mapping of Java threads to native threads. The above should be adjusted accordingly, but that would only change the wording, not the intent of the description. > So I'm still confused about the docs. I'm confused about you being confused; why do you think the example in the Tomcat docs is overly complicated? - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org