Results 1 to 5 of 5
Thread: Stoping thread?
- 04-11-2010, 02:35 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 23
- Rep Power
- 0
Stoping thread?
Please help me, i want to stop a thread when i press a button and its using actionperformed. But when i am implementing it it give me an exception.
Code is like this
Java Code:MThread m = new MThread(); new Thread(m).start(); JButton b = new JButton("Stop"); b.addActionListener(this); public void actionPerformed() { if(e.getSource() == b) new Thread(m).stop(); }
-
1) You know that when you create a new Thread object, it is completely distinct from the previous Thread object, that calling methods on the one will have no effect on the other.
2) Also, the API will tell you that Thread#stop() has been deprecated, why it has been deprecated and what to do instead.
I recommend that you create a small compilable and runnable demo program and post it here, an SSCCE (see the link below).
- 04-11-2010, 02:46 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,395
- Blog Entries
- 7
- Rep Power
- 17
-
Jos, I beat you in this one, but you got the draw in the other thread. So I guess that makes us even.
- 04-11-2010, 03:03 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,395
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Difference between Thread.yield() and Thread.sleep() methods
By Nageswara Rao Mothukuri in forum New To JavaReplies: 12Last Post: 07-30-2010, 05:37 PM -
Trigger main thread method from secondary thread?
By DigitalMan in forum Threads and SynchronizationReplies: 8Last Post: 01-26-2010, 02:13 AM -
Stoping repeated entries in JComboBox
By MasterDeveloper in forum AWT / SwingReplies: 5Last Post: 04-05-2009, 12:07 PM -
If JNI thread call the java object in another thread, it will crash.
By skaterxu in forum Advanced JavaReplies: 0Last Post: 01-28-2008, 07:02 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks