Question

i would like to check what it means to have a synchronized instance method in a Struts 1 Action class?

Something like

public synchronized String checkAction(){ ... } 
Was it helpful?

Solution

It means the checkAction method is going to be synchronized by the enclosing Object's intrinsic lock (The Action class Object's lock). So only one thread at a time will be able to access the checkAction method.

In Struts 1 the Action class is not thread safe. So multiple threads (e.g. servicing multiple requests) will access the same instance of the Action class. Does the method need to be synchronized? I'm not sure - only you can tell by what's happening in the method. So long as it isn't accessing instance variables of the Action class or doing something which can only be done by a single thread at a time, then synchronization is probably not necessary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top