• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A lock could not be obtained within the time requested

 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Think of how dumb the average person is. Mathematically, half of them are EVEN DUMBER. Smart tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic