I have a Java application named 'X'. In Windows environment, at a given point of time there might be more than one instance of the application. I want a common piece of code to be executed sequentially in the Application 'X' no matter how many instances of the application are running. Is that something possible and can be achieved ? Any suggestions will help.
Example :- I have a class named Executor
where a method execute()
will be invoked. Assuming there might be two or more instances of the application at any given point of time, how can i have the method execute()
run sequential from different instances ?
Is there something like a lock which can be accessed from two instances and see if the lock is currently active or not ? Any help ?