title: Restrict multiple instances of an application in java
body: <p>I want to prevent multiple instances of application being launched in java. I know 2 methods for this:</p>
  
  <ol>
  <li>locking file</li>
  <li>locking socket </li>
  </ol>
  
  <p>But which is one is more efficient and good to use? Which one should I use? </p>
  
  <p>Any other solution to do the same are also welcome.</p>