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).
- 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
Joined: Oct 30, 2001
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 ]
Joined: Sep 29, 2002
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.
Joined: Oct 30, 2001
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.
subject: A lock could not be obtained within the time requested