How can two application instances interact in Java?

I am developing a new Java Desktop application. Something like a media player. I want to load most of the resources in the background when the computer starts. But users can disable this option in the application or use some other utility. So what do I want to do if the application prohibition instance is already running and the user starts the application again, then can I talk to the instance that is already running so that it can launch a new window?

+4
source share
3 answers

The best known way to do this is to open ServerSocket when the first application is launched in a well-known port.

If ServerSocket is not loading, it is possible because the instance is already running.

In this case, you can open Socket and start communicating your orders between both instances.

But you can also use much more complex solutions such as Jini or JGroups.

+7
source

Burn the application so that it has a server part

When it starts, try contacting the server (if it is already running), and if this is done, the server should open a new window, and the client should die

This will give you an overview:

http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html

+3
source

You can use ports.

+1
source

Source: https://habr.com/ru/post/1310493/


All Articles