title: How to ensure only one instance of a java program can be executed?
body: <p>It is requited that only one instance of a JAVA program can be executed at a certain time. I have observed a good number of solutions proposed in stack overflow in different earlier posts.</p>
  
  <p>The solutions are based on:</p>
  
  <ul>
  <li>By opening socket: To open a socket connection. </li>
  <li>Based on the file locking: To create a temporary file and to hold a lock. And to add a shutdown hook to unlock that file when the JVM shuts down.</li>
  </ul>
  
  <p>I do not want to use port locking as it can cause a possible conflict in ports usage. </p>
  
  <p>So I was thinking to use file locking. After searching a bit, I have found the proponents of the port locking based mechanism has mentioned file locking can be unreliable if application crashes and for other IO errors.</p>
  
  <p>What I need is to find a solution which will work consistently in cross platform and in multiple JDK. My intended platform is Windows and Linux and JDK is Sun and IBM JDK.</p>
  
  <p>Can anyone shed some light on to this?</p>