views:

345

answers:

1

I'm seeing OraclePreparedStatement executeQuery() exhibit serialization. That is, I have two queries that I want to run concurrently against an Oracle database, using the same connection. However, the OraclePreparedStatement seems to explicitly prohibit concurrent queries.

My question is: Is this serialization a necessary artifact of running both queries on the same connection, or is this configurable?

I've tried setting readOnly to true for the duration of the two queries, but they still serialize.

+3  A: 

I believe that Oracle's Connection class methods are synchronized. see this api description. This would then be an artifact of using the same connection, and not a configurable property. If you need to get around this limitation, you can either use 2 connections or look into connection pooling if you want a more flexible solution.

akf
Thanks. Both threads are using the same connection from the pool. It would take a little re-working to avoid the use of a temporary table, so I was hoping for an easier solution before going down that road.
Don Branson
if that is the case, you may want to reconsider the design of the pool. the pool shouldn't give out connections that currently are in use.
akf
It's not. I'm reworking a long-running task that issues about 8 queries sequentially. A couple of them can be done concurrently, so I was starting two threads to run two queries concurrently, and handing the queries the same connection. Now the code grabs two connections, so each thread has its own connection. Works like a champ.
Don Branson