To control running instances of one program
The config item 'singleinstance' is to allow only one instance can be running at the same time. By default, the number of running instances are not limited.
The 'singleinstance' can be followed by one of 3 values:
The default value is 'false', there is no limit on how many instances running at the same time.
The value 'true' means only one instance are allowed at the same time, so the second instance of the same program will fail to start.
The value 'handover' means the second instance handover its command line arguments (String  args) to the first instance without starting a JVM.
The value 'custom' is to enable the feature of communication between instances of the same program, then java program can control the running instances in your own way easily.
singleinstance custom[since 2.1.5]
The value 'singleinstance custom' is to enable the communcation between instances of the same program. Through the commucation API, java program can
- Get the first instance (pid) and current instance (pid) and all running instances (pids) and their start order. So java program can know whether this is the first instance by comparing the "first == current", and java program can know its start order by finding itself in all instances.
- Send a message to another instance specified by the pid, the message can be any java serializable objects.
By the help of communication API, java program can discuss between instances and decide which one exit and which one keep running, and leave some last words to the other instance before exit.
singleinstance handover[since 2.5.5]
The value 'singleinstance handover' is to let the second and following instances handover their command line arguments to the first instance without starting a JVM. Through the commucation API, the first instance could receive and reply the second instance.
After the command line arguments is sent to the first, the second instance will wait the reply from the first, untill timeout, for about 50 seconds.
For more information about integrate with commucation API,
- See Instances