Results 1 to 4 of 4
Thread: Problem in Multi threading.
- 03-22-2010, 04:15 AM #1
Member
- Join Date
- Feb 2010
- Posts
- 15
- Rep Power
- 0
- 03-22-2010, 08:15 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
1. You can't (without using inherently unsafe/dangerous deprecated methods).
2. You can't. Recreate it.
If what you really need is a thread that processes something then "goes to sleep" until the next item to process comes along, use a queue.
- 03-23-2010, 05:32 AM #3
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
To kill a thread, you need to provide some kind of method that causes an exit of the run loop.
Java Code:class KillableThread extends Thread { boolean keepGoing = true; boolean exit = false; public synchronized void run() { while(keepGoing) { ....do something useful and then ... try { wait(...maybe have a timeout...); } catch (InterruptedException iex) {...handle this} } exit = true; notify(); } public synchronized void kill() { if(keepGoing) { keepGoing = false; notify(); if(!exit) { try { wait(); } catch (InterruptedException iex) {...do somethign} } } } }
- 03-23-2010, 04:42 PM #4
Similar Threads
-
Newbie to multi-threading please direct me :)
By kminev in forum Threads and SynchronizationReplies: 8Last Post: 11-18-2009, 06:11 PM -
Multi-Threading and process control in Java
By mo_mughrabi in forum Advanced JavaReplies: 2Last Post: 08-16-2009, 01:47 PM -
Problem in threading
By saurabh in forum Threads and SynchronizationReplies: 6Last Post: 12-01-2008, 08:16 PM -
Order Management System Java Developer NYC-Core Java/Multi-threading/Socket Developer
By evanp in forum Jobs OfferedReplies: 0Last Post: 07-22-2008, 04:39 PM -
question about Multi threading in Java
By fred in forum Advanced JavaReplies: 1Last Post: 07-24-2007, 01:55 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks