Skip to main content

Posts

Showing posts from February, 2018

Creating single instance of Java Application

Prerequisites: Basic Java project creation Knowledge in SWT/JFace dialog There are several ways to enforce a single instance of java application. Here I am going to explain about one of the most used way to create a single instance for any java application by using Server Socket class. Create a simple Java project. Call the below API before the initiation of the project. Surround this API in try/catch block so that if the API succeeds it will execute the application else custom user understandable error message is displayed.  Explanation: By creating a server socket instance by passing the port no and local address of the system as parameter one can monitor the application running in that specific port address in that specific system. If user tries to launch another instance of an application server socket throws exception.java.net.BindException: Address already in use: JVM_Bind exception . For the complete source code of this application please clone/down