• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Lock Table issue: Need help

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am trying to get a table lock in a threading environment. I am concerned that if my thread dies without closing the connection(releasing the lock) than How will i be able to release the lock. OR does oracle has some settings through which the lock is released by itself after some timeout.

I know its a bad idea to lock the table but my requirement is such that I have control the sequence of insertion or update to the table. The process for locking and releasing is very small.

Appreciate your help

GUL
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gul,

I believe the lock will be released when your session dies (which would not necessarily be when your thread dies). If you start your session (connection) with a short timeout that may limit the life of the lock. You'll have to check the docs, however, to ensure the timeout is passed on at DB level.

As you say, taking out explicit locks is a BAD idea and smells of poor design. I would think hard to find an alternative solution before choosing that option.

Jules
 
Gul Khan
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Julian for the reply. I am still looking into other alternatives to Table Lock. I have to control to synchronize the access to the table either at MQ Series level, Application level or DB level.
Message Q level which I am still investigating, Application level is almost impossible as there are Message Driven Beans across the cluster who can access the database concurrently. So initial investigation left me with the choice to lock the table that every one is trying to access.

Thanks for the help again.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am I right to assume that the standard locks the database takes out during a transaction are insufficient? Have you looked at augmenting the transaction isolation level for transactions affecting your problem table? I assume you're aware that by serializing access to a transaction table you're creating a potential performance bottle-neck in your application.

It shouldn't be too hard to serialize access to a DB table in the Java code - just synchronize on some common object around each JDBC execute call involving the table. Personally I think that's a really bad idea, however. I've seen it done before and it's typically the recourse of Java developers who don't understand (read "are scared of") databases.

Jules
 
Gul Khan
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We cannot do it from Java code because the application is running on a Cluster and there still can be more than one processes inserting into the table.
I did find a work around without locking any table or record through the Program but we had to compromise on the process time.
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic