Is there a way to make a block of code threadsafe so that even if the requests are coming from two different JVMs altogether (where the EARs are deployed having the same code) they do not access the code in parallel?
Separate JVMs would of course have separate object instances and separate Threads so this gets tricky. Probably some outside entity will have to be involved, say a database or a file representing a "token" which both JVMs can see.
Exactly what is the problem you are trying to solve?
subject: Achieving threadsafe behavior for threads coming from two different JVMs