Just a question about synchronization.
It seems difficult for me to use method level synchronization in the service layer because of the programming to interfaces design choice.
I cannot add the synchronized keyword to the method in the implementation class of my service. If I do so, my service is not fully synchronized because transaction commit will occur outside synchronization.
As I don't want to let synchronization demarcation to the client side, the only solution I can find is using a synchronization keyword in my service declaration in my applicationContext.xml
Does this makes sense ? Do you have any other solution to my problem.
Here is a bit of code to explain my problem
Code:
public class Action
{
public void process()
{
// I want this call to be synchronized but don't want to declare synchronization here
getMyService().doSomething();
}
}
public interface MyService
{
void doSomething();
}
public class MyServiceImpl implements MyService
{
// Synchronization here is not truly effective as transaction commit
// occurs outside the method
public synchronized void doSomething()
{
// do
}
}