I am using JDBC to talk to my Postgres database. If my entire app runs off a single connection, ie there is only ever one call to;
DriverManager.getConnection("jdbc:postgresql://host:5432/database", user, pass);
But this Connection
object is shared across multiple threads in the Java, am I right in assuming that any attempt to use SQL transactions (BEGIN
and COMMIT
style) is only going to be very confusing and broken, given the potential for the Java threads to interleave? Does the Connection
object 'know' which Java thread is using it to make queries?
Should I have one Connection
object per Java thread and use the SQL transactions that way? Or should I perform all my transactional isolation in the Java using synchronized
?