0

I wrote a java swing application and it has some simple specifications. These are the specifications:

  1. From very beginning of the application it has a privilege to add to the system tray.
  2. The application never exit when Main JFrame is closed. It means, it is still running.

Now my problem is how to check it is still running or not and if it is running, how could I run Timer inside it?

Do you, Java experts have any ideas about this problem?

12
  • 2
    If your swing application is the only java application running on that host and if you are running on windows you can check in the task manager or with ps on unix/linux system's if there is a java process that is running. You can also launch jconsole on the host and see what are the local java process apart from jconsole itself. Commented Apr 29, 2016 at 10:50
  • 2
    You could use a file lock (check file existing and create on start), but it is not reliable when the app crashes. Unfortunately there is no simple way to check if the app is running without using some OS-specific calls. stackoverflow.com/questions/660205/… - here are some examples. Commented Apr 29, 2016 at 10:53
  • 1
    You might try using the inbuilt functionality of the SingleInstanceService of the JNLP API (available to desktop apps. launched using Java Web Start). OTOH I don't know how well JWS would integrate with the requirement for entry in the system tray.. Commented Apr 29, 2016 at 11:19
  • 2
    "Can you provide me an example code ?" Did you follow the link? More generally, don't ask for code or examples on SO. It is a Q&A Site, not a help desk. Commented Apr 29, 2016 at 11:22
  • 2
    If you only want a "single" instance of the application to ever be running there are a number of things you could do. You could open a socket on a specific port, if you can do this, then no other instances of the application are running; you could use a lock file, which if present, means another instance of the application is running Commented Apr 29, 2016 at 11:34

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.