aspose file tools*
The moose likes JDBC and the fly likes A lock could not be obtained within the time requested Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "A lock could not be obtained within the time requested" Watch "A lock could not be obtained within the time requested" New topic
Author

A lock could not be obtained within the time requested

Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
I have a tricky problem with some JDBC code. I am getting an exception with the message "A lock could not be obtained within the time requested".

My application is very multi-threaded, so I thought I must have some sort of database-related deadlock, where two threads try to lock the same tables in different orders. However, a full thread dump at time of exception shows that only the failing thread is doing JDBC. All other threads are doing unrelated stuff (mostly just waiting).

The database is JavaDB (a.k.a. Derby).

Any ideas?

Exception occurred: java.sql.SQLTransactionRollbackException (to be caught at: org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(), line=-1 bci=527)"thread=JobLogger0005", org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(), line=-1 bci=526



Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
We need more information, such as:

- are you using an app server
- are you using connection pooling
- what transaction timeout setting do you have
- what is the code which is failing


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
I'm not sure that you do actually want all the above-listed information. However, I do now realise that I didn't explain what my application is.

The database is embedded in the application and used exclusively by the application. Therefore, any operations that are occurring on the database must be being done by a thread of the application.

That's why it is a confusing problem. Only one thread is doing database operations, so I can't see why it should be having to wait for locks.

I suppose it doesn't hurt to post the failing code: -

[ January 16, 2008: Message edited by: Peter Chase ]
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
If you are really certain that only one thread has been doing DB access, then perhaps you have a timeout.

If there are multiple threads accessing the DB, then some change to the isolation level may help. Sorry I can't assist further as I've no knowledge of Derby.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
I definitely have a time-out. That's the whole point. But it's timing-out because it can't get a lock on a table, even though no other thread is supposed to be using that table, at that time. Of course, in the past, various threads have been doing DB operations, but they aren't at the time of the problem.

As it happens, though, I think I know what's going on. I think I've got an unclosed transaction somewhere, on the same table. Fixing the problem does not look easy, but at least I know what type of problem it is.

So thanks for your interest, but I think I can in fact take it from here.
 
jQuery in Action, 2nd edition
 
subject: A lock could not be obtained within the time requested