multithreading - Multithreaded JDBC -
What is the best way to handle JDBC with many threads? There are several threads in my database together. With a single connection and statement I get the following error message:
org.postgresql.util.PSQLException: This result is offset.
Should I use multiple connections, multiple descriptions or is there a better way? My initial thought was to use a statement per thread that guarantees a set result set.
You should use a connection per task if you use connection pooling Can not use ready-made statement prepared by the connection. All object connections created by the connection (ResultSet, PreparedStatements) are invalid for use after returning to the pool.
So, it's the same
public zero getSomeData () {connection conn = datasource.getConnection (); Preparedness; Try {st = conn.prepareStatement (...); St.execute (); } Finally {closed (cents); Conn; }}
In this case all your DAO objects do not take connection, but Datasource Object (java.sql.DataSource) which is actually the pool connection factory. And in each method you get the connection first, do all your work and close connections. You should return the connection to the pool as soon as possible. After returning the connection it can not be physically stopped, but it was started again (all active transactions were closed, all session variables were destroyed.)
Comments
Post a Comment