Hi,
may we use the java keyword "synchronized" on a method of a SLSB to ensure that several statements get executed all together or not at all?
I have a method in a SLSB, which updates a counter kept in an Entity bean, if some condition is fulfilled.
Afterwards the counter is increased. I want to ensure the integrity of the counter. Because several threads can and will access the method.
What would you suggest?
This how the pseudo code block looks like:
public String methodDoesNotBelongToSLSinterface(EnityBeanWithCounter eb) { ... ... // make sure that no race condition can occur using synchronized(this) { statement1; statement2; ... statementN; // Increase counter if successful if (someCondition) eb.setCounter(eb.getCounter + 1); } .... .... }