File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A lock could not be obtained within the time requested

 
Peter Chase
Ranch Hand
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Peter Chase
Ranch Hand
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic