Maksymilian Majer
Maksymilian Majer

Reputation: 2956

Java WebStart disallow multiple instances

My WebStart applet can't work in two browsers or two browser tabs/windows. Therefore I don't want to allow running multiple instances of my applet.

Does anyone know a way to prevent a second instance of an applet from running or check if an instance of my applet is already running during initialization of a new one?

Upvotes: 2

Views: 997

Answers (1)

Mikel
Mikel

Reputation: 460

Use the SingleInstanceService. See an example here:

But you have to remember to unregister the instance later. So maybe a better way (it is a hack :) ) would be to try to listen to a TCP port in the beginning and if it fails you do not start. In this way if you forgot to stop listening to the TCP port before exiting you will still be "unregistered" because the TCP port will be closed automatically by the OS.

Upvotes: 3

Related Questions