|
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
}
|