Question

I'm trying to understand how deadlocks can be managed using ESQL. I created 2 concurrent processes that try to update a "customers" table, exactly like the example given in O'Neil's book "Database": http://books.google.ca/books?id=UXh4qTpmO8QC&pg=PA298&lpg=PA298&dq=%22deadabort%22+oracle&source=bl&ots=2QF7eSbaW6&sig=IcEZtSXINKrOVro1UN-ShlNsAak&hl=en&ei=9BPvTKPfMtP4nwfqu_X1Cg&sa=X&oi=book_result&ct=result&resnum=1&ved=0CBcQ6AEwAA#v=onepage&q=%22deadabort%22%20oracle&f=false

But for some reason, the process 2 that is waiting for 1 to finish blocks at the statement "exec sql update customers", and never enters the "if(sqlca.sqlcode == DEADABORT)" statement. Hence, I can never manage the deadlock.

Does anybody have an idea?

Was it helpful?

Solution

Without seeing the code it is hard to comment, but a database deadlock error is going to be very hard (if not impossible) to produce in a single threaded program even if you have two connections.

In a single threaded program

  • Connection A locks row R1.
  • Connection B locks row R2.
  • Connection A tries to lock row R2 and waits

It hasn't reached the deadlock condition because Connection A is simply waiting on Connection B. The database doesn't know that both database connections are from a single process/thread so it doesn't know they are deadlocked.

This issue crops up with connection pools sometimes. One end user session locks a shared resource using a connection from the pool. The other pool connections fill up all waiting on that shared resource, and then that original end user session can't get a connection pool thread to release the resource.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top