Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Do Threads Block on Database Resources?

 
savas karabuz
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Brahim Bakayoko
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic