Restrict multiple instances of an application in java

前端 未结 8 1101
温柔的废话
温柔的废话 2020-12-03 22:55

I want to prevent multiple instances of application being launched in java. I know 2 methods for this:

  1. locking file
  2. locking socket

But

相关标签:
8条回答
  • 2020-12-03 23:29

    My vote goes to locking on a port (i think this is what you mean by socket). I don't know the exact reason for this. But in fact i come across only this as a solution in most practical projects. Though i will be happy to hear the alternative ways.

    0 讨论(0)
  • 2020-12-03 23:31

    If you deploy with Java WebStart the SingleInstanceService does this.

    See http://download.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/faq.html#218

    0 讨论(0)
提交回复
热议问题