View Single Post
  #1 (permalink)  
Old 10-07-2008, 06:41 PM
mrhyman mrhyman is offline
Member
 
Join Date: Oct 2008
Posts: 8
mrhyman is on a distinguished road
Thread Safe Methods / Locks
I am new to java and I have a question about synchronizing two methods that updates some variables. I am not sure how to perform this operation so that it is thread safe. I cannot use Synchronize Method itself, rather I should use Semaphores or Lock(but avoid Deadlock).

Any help would be appreciated.


buyItem() {
....

sellItem();


//do some transaction here
//Example Update Account Balance
....
}


sellItem() {
//do some transaction here
//Update Account Balance
}
Reply With Quote
Sponsored Links