Best ways to write a method that updates two objects in a multithreaded java environment?
Posted
by DanielHonig
on Stack Overflow
See other posts from Stack Overflow
or by DanielHonig
Published on 2010-06-02T14:25:46Z
Indexed on
2010/06/02
14:34 UTC
Read the original article
Hit count: 214
Suppose we have a class called AccountService that manages the state of accounts.
AccountService is defined as
interface AccountService{
public void debit(account);
public void credit(account);
public void transfer(Account account, Account account1);
}
Given this definition, what is the best way to implement transfer() so that you can guarantee that transfer is an atomic operation.
I'm interested in answers that reference Java 1.4 code as well as answers that might use resources from java.util.concurrent in Java 5
© Stack Overflow or respective owner