Re: Is it thread-safe to pool the PreparedStatement?
Brian Maso <[email protected]>
| Newsgroups | gmane.comp.windows.devel.java.advanced |
|---|---|
| Message-ID | <20070820173809.FVDN9971.fed1rmmtao101.cox.net@fed1rmimpo01.cox.net> |
At first I thought this would violate JTA requirements -- but looking at the JTA spec it seems that multithreaded access to a resource manager is supported, so there's no problem there. The JDBC spec says that a PreparedStatement can only be involved in a single database interaction at a time. This means that, while reading the ResultSet response to a SELECT query put forth through a particular PreparedStatement, you can't send another query through the same PreparedStatement because the existing ResultSet will be closed automatically. So your PreparedStatement pool needs to ensure exclusive access to a single thread until the thread is done with the statement, before returning the statement back to the pool. Sounds like that kind of assurance might not be there. Brian Maso At 09:46 AM 8/20/2007, you wrote: >I just join a project, this existing team member of this project >concern performance a lot so their pool all PreparedStatements into a >map (probably not a nice optimization, but I have no say about that) >when the application start. And then reuse those preparedstatement >again and again. > >I haven't get time to check all method call using those >preparedstatement are synchronized properly. If that is not the case, >is it thread-safe to pool the PreparedStatement? > >=================================== >This list is hosted by DevelopMentor® http://www.develop.com > >View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com