Here is a solution that is a one-liner, in that you only have to add one extra line. (You do have to add synchronized
and throws InterruptedException
to your main
declaration though.) Also, it does not need access to, or even knowledge of the threads in the library you are using.
public static synchronized void main(String[] args) throws InterruptedException{
...
YourMainClass.class.wait(); // wait forever
}
It assumes you will never call notify
on your main class and that you want to exit if you get an InterruptedException
. (You can add a while (true) { ... }
around the wait
line if you really want to guard against that.)