Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is there possible of synchronize Execuation of Java program file

 
Parshuram Walunjkar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friend's,
I want to synchronize the execution of java program main method. I means if I running the Hello. java from one console and I want don't want to run that program from another console.
Is this possible in java?
Regards from
Parshuram Walunjkar
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with that is that they are running from separate processes in their own JVMs.
I would guess that you could create some persistant flag in a database or file and have the main method check that flag as it's first step. If it is not set - then set it (making sure that you write it back out to the file) and continue running. When complete you would need to unset the flag.
If it is already set just exit gracefully.
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could have the program open a socket (or start an RMI server) when it starts. New processes can check for previosly running servers and perhaps even send some commands (i.e. if it's a file editor, there could be a way to open a file in a pre-existing process).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic