There is no previous instance in Java, but you can create a pid file in the temp directory (or / var / run). (And make it File.deleteOnExit() to clear it anyway on exit)
To move an existing window up, you can notify the program yourself, through a named pipe, unix socket, or calling remote Java methods, etc. A simple and dirty way is to write to a small file, for example $TEMP/foobar-app.bring-to-top , and the program should periodically test this small file, if this happens, return the window up and delete this small file.
I think Java cannot process signals, i.e. kill -HUP PID may not work for Java applications. Even if this is possible, not every OS has signals.
Xiè Jìléi
source share