aspose file tools*
The moose likes JDBC and the fly likes Do Threads Block on Database Resources? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Do Threads Block on Database Resources?" Watch "Do Threads Block on Database Resources?" New topic
Author

Do Threads Block on Database Resources?

savas karabuz
Greenhorn

Joined: Feb 24, 2004
Posts: 16
Hi all,

Suppose a thread opened a connection to a database and acquired an exclusive lock on a table to delete some rows.

What happens when a second thread tries to select a row from that locked table(or to update a row of the table) before the first one releases the lock by a commit or rollback?

Does it wait for the lock of the table to be released(namely,blocks?), does it throw an exception, or something else?

Thanks in advance...
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
This doesn't look very much like a SCJP type question so I'll move it somewhere like here in JDBC.
[ June 30, 2004: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Brahim Bakayoko
Ranch Hand

Joined: Aug 29, 2003
Posts: 155
Originally posted by savas karabuz:
Hi all,

Suppose a thread opened a connection to a database and acquired an exclusive lock on a table to delete some rows.

What happens when a second thread tries to select a row from that locked table(or to update a row of the table) before the first one releases the lock by a commit or rollback?

Does it wait for the lock of the table to be released(namely,blocks?), does it throw an exception, or something else?

Thanks in advance...


The other threads wait (if serializable transaction for select or if insert or update) for determined amount of time unless the "nowait" is specified in the sql statement.
Last, the transaction settings on the datasource and/or database will determine what type of operations will be possible when a row or table is locked.
[ June 30, 2004: Message edited by: Brahim Bakayoko ]

SCJP, SCWCD, SCBCD, IBM CSD WebSphere v5, <br />A+, MCP 2000 and 2000 server, CST, and few incompleted certification tracks.<br /> <br />Ivory Coast<br /> <br />Analyze your web Request/Response @ <a href="http://webtools.servehttp.com" target="_blank" rel="nofollow">http://webtools.servehttp.com</a> down for a while...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Do Threads Block on Database Resources?