For example, in the following code:
public boolean foo(int val) {
//...
helper.set(val);
int val2 = helper.get(val);
//...
return (val==val2);
}
where foo is a method of a stateless session bean, and helper is the instance of a help class, a singleton object.
Can foo always return true if i don't use "synchronized(helper)"?
The answer is no because EJB's act sort of like threads - everyone can have their own ejb instance, and if multiple ejb instances (like multiple threads) act on shared data (such as the private member of a singleton) there will be concurrency issues.
How to synchronize EJB?
public boolean foo(int val) {
//...
helper.set(val);
int val2 = helper.get(val);
//...
return (val==val2);
}
where foo is a method of a stateless session bean, and helper is the instance of a help class, a singleton object.
Can foo always return true if i don't use "synchronized(helper)"?
The answer is no because EJB's act sort of like threads - everyone can have their own ejb instance, and if multiple ejb instances (like multiple threads) act on shared data (such as the private member of a singleton) there will be concurrency issues.
How to synchronize EJB?