my dog learned polymorphism*
The moose likes JDBC and the fly likes Single connection with parallel queries Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Single connection with parallel queries" Watch "Single connection with parallel queries" New topic
Author

Single connection with parallel queries

Claude Brisson
Greenhorn

Joined: Nov 03, 2004
Posts: 4
I always thought of a connection (i.e. a TCP socket channel opened with a couple {login,password} to the database server) as allowing parallel queries (i.e. queries launched by parallel threads in the same process), since a good "connection" paradigm is one that allows to reduce the redundancy of connection infos in the client program.

But I experienced that with Oracle [9.2.0.1.0] and JDBC, parallel queries are not supported (a long query makes another short one wait for itself).

It would mean that connection pools are mandatory in a multi-threaded application... sounds rather strange to me, as if I had to log on again each time I open a new browser window on my desktop, for instance.

What I'd like to know is if this behaviour is specific to Oracle+JDBC (and if others have experienced similar issues with Oracle).

Thanks for your answer.

Claude
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
dont know i got you or not.

just suppose we are signed in on sql plus* and doing work. and then we start one more instance of sql plus*. it will ask you to log in seperately.

and for multi-threaded transaction there should be more then one connection. yes if it is about one thread but multi transaction then one connection would be Ok. but if different threads use the same connection then it would be terrible.
Claude Brisson
Greenhorn

Joined: Nov 03, 2004
Posts: 4
dont know i got you or not.

just suppose we are signed in on sql plus* and doing work. and then we start one more instance of sql plus*. it will ask you to log in seperately.

Of course. It was a metaphore, I was picturing myself as the JDBC client app.
and for multi-threaded transaction there should be more then one connection. yes if it is about one thread but multi transaction then one connection would be Ok. but if different threads use the same connection then it would be terrible.

Of course not. That's why java synchronized blocks are made for. To put it another way, JDBC Connection objects SHOULD be re-entrant since I don't know why an application (multi-threaded or not) would have to log on several time just because it needs to use different statements in different threads. Hope I make it clear.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Claude Brisson:

Of course not. That's why java synchronized blocks are made for. To put it another way, JDBC Connection objects SHOULD be re-entrant since I don't know why an application (multi-threaded or not) would have to log on several time just because it needs to use different statements in different threads. Hope I make it clear.


I was talking about the scenerio where two or more threads using same connection object simultaneously. then i might result in a disaster. But ofcourse we can use the same connection object for different statement even in a multi-threaded environment.

however, we have connection pooling mechanism in which we use the connection object again and again. but when free. we dont use it while it is serving someother thread or request.

And about synchronized. yes it would keep our connection object thread-safe. but again it means different thread are not using that connection obj simultaneously. and there would be a performance lack definitely.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
you can check with "Aqua Data Studio", free for trail. it is a DB Client which uses JDBC.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


It would mean that connection pools are mandatory in a multi-threaded application... sounds rather strange to me, as if I had to log on again each time I open a new browser window on my desktop, for instance

Well, connection pools are not necessarily mandatory (they may well be expedient though), but multiple connnections are in an multithreaded environment. Connection reuse is fine, but queries will never by run in parallel (from JDBC's point of view anyway - what happens in the BD might be different). It's not just Oracle either, every database I know behaves the same way. A single thread accessing the DB == a single DB client. Think about how JDBC handles transactions - a transaction is against a Connection object, if you have concurrent SQL statements in the same Connection, which one does the transaction apply to?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Single connection with parallel queries