开发者

Netbeans problem: Is some thread still running after UI exits?

I have a strange problem with both Netbeans 6.9.1 and 7.0.1 IDEs. I have a project with a few classes and from the UI class I call an instance of another class that performs much of the program's work. I select the green arrow (Run Main project or F6 button) and the application executes and I am presented with the UI of my Java app. I have created an instance of Thread in the UI class and when a button is pressed code executes and the new thread is called with thread.start(). Control is transferred to the other class where I have a run() method calling my main method that processes the stuff I pass to it. This is working fine (I think) but for one problem: When the UI has finished executing it does not exit because I could need to re-run the UI again with other inputs etc. This is making the IDE behave as if the program is still executing and the Run main project, Clean and Clean and Build, and debug buttons are shaded/disabled and the only buttons I have are the Profile and paste history. I can re-run the app by using the double-arrows on the console output part of the IDE.

What can I do to make the IDE release the thread/s that are maybe still run开发者_运维百科ning in the background as in order to get the full functionality I have to restart the IDE.

Thanks for any info or help.


Use join() to wait for your thread to finish: http://www.java2s.com/Code/JavaAPI/java.lang/ThreadjoinUsingjointowaitforthreadstofinish.htm

Or try to make it interruptible: www.java2s.com/Code/JavaAPI/java.lang/Threadinterrupt.htm

Simpler/cleaner and better: use a Swing Worker Thread http://java.sun.com/products/jfc/tsc/articles/threads/threads2.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜