Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lock Unlock record some confusion.

 
Shivaji Bhosale
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I yet not functionally started assignment, but doing groundwork, writing small small patch of code with db.db.
I confused with implementing with Lock & Unlock methods since they ought to be called from client.
In order to track the client while executing Locking / Unlocking mechanism over Database record, Client Id has to be passed. By which way we can pass client id to the server, So we can ensure this client acquired the lock on the record.
Since we have lock / Unlock / Modify are separate methods how come we can ensure thread safeness by Synchronized(DataInfo_obj).
I can find the way out.
 
pramila thakur
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You can find which client wants to lock the record by calling this.
Thread caller = Thread.currentThread();
then find out if the caller is same as owner then you need not wait to lock again, if not wait for the record to be unlocked.
Thanks.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use getCurrentThread() if you are using Object Serialization, if you chose RMI you need to read most of the other Lock, Unlock posts on this newsgroup. The answer is out there.
We are not alone
Mark
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Spritzler:
You can use getCurrentThread() if you are using Object Serialization
But can you? Do you have a rock-solid guarantee that no two Threads are identical in different JVMs?
- Peter

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know. I think that all comes down to how JVM creates thread identifiers. Or would the chance of them being the same 1 in infinity? I wonder if they are created using a random generator based on the time in milliseconds?
Anyway I am using RMI, so I didn't have to come across that issue. Maybe I could use that as a consideration on my essay exam on why I chose RMI.
Just a thought, I don't know .
Mark
[This message has been edited by Mark Spritzler (edited October 19, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic