Hello there.
I had a simple program which used the "suspend" and "resume" methods from Java's Thread class.
Those two methods are deprecated now because they are deadlock prone.
I would like to re-write my code to not use those deprecated methods anymore but I am not 100% sure how the ideal implementation would look like.
I have a very simple test program which shows the behaviour I want to achieve.
public class ThreadTest { private static Thread t1; public static void main(String[] args) { t1 = new Thread() { public void run() { threadLoop(); } }; System.out.println("Start"); t1.start(); } private static void threadLoop() { int i = 0; while (true) { i++; if (i == Integer.MAX_VALUE) { openPopup(); i = 0; } } } private static void openPopup() { Popup popup = new Popup("ALARM!", "This is an important error message!", 256, 256); popup.addWindowListener(new WindowListener() { public void windowOpened(WindowEvent arg0) { } public void windowIconified(WindowEvent arg0) { } public void windowDeiconified(WindowEvent arg0) { } public void windowDeactivated(WindowEvent arg0) { } public void windowClosing(WindowEvent arg0) { } public void windowClosed(WindowEvent arg0) { t1.resume(); } public void windowActivated(WindowEvent arg0) { } }); t1.suspend(); } private static class Popup extends JFrame { ... // this is not important } }
Thank you very much in advance.