Hi folks, my requirement is like from main thread i will start new thread ,Once the new starts the main thread has to be in wait state..and once the new thread stops i have to start the old one again How to go about it.. The following is where i require.. 1)From the main program i will call a Jdialog window.Now the main thread had to wait. The JDialog has to be in a seperate thread, once i click yes or no, then main thread to continue its execution.How to go about?? Thanks & Regards, silva.
Two things. First, why would you spawn a second thread when the process evidently doesn't need one at all? Second, any Swing (or AWT) widget lives its entire life in the Swing event dispatcher thread - Swing isn't threadsafe. If you want your main thread to wait for an GUI event, you can create a new Object() as a semaphore (or recycle an existing object), wait() on it in the main thread, and have the button event handler call notify() on it. - Peter
Or you could just use t1.join() in your main method after you start it. That way the main thread will wait until the other is completed. Won't stop other threads from accessing the thread object, but main won't do anything until the thread stops. Jason