Results 1 to 3 of 3
Thread: Procedure to start Thread?
- 04-23-2010, 12:01 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 23
- Rep Power
- 0
- 04-23-2010, 12:28 AM #2
Senior Member
- Join Date
- Mar 2010
- Posts
- 266
- Rep Power
- 4
you cant. After run() method completes, the thread is dead and cannot be re-started. You'll have to create a new object and start another thread.
Why would you want to do this though? If you're trying to take care of pause/resume situation, the following code works for me:
Java Code:class MyThread implements Runnable { private Thread theThread; private boolean isPaused; public void start() { isPaused = false; isRunning = true; theThread = new Thread(this); theThread.start(); } public void shutdown() { isRunning=false; theThread.interrupt(); this.join(); } public void pause() { isPaused = true; } public void resume() { isPaused = false; synchronized(this) { this.notify(); } } public void run() { while(isRunning) { synchronized(this) { while(isPaused && isRunning) { try { this.wait(); } catch (InterruptedException ex) { // ignore } } } if(isRunning) { // do actual work here } } } }
- 04-23-2010, 05:05 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 23
- Rep Power
- 0
Similar Threads
-
call a pl/sql procedure through a jsp page
By mudit222 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 04-20-2010, 08:02 PM -
migration of Ms-sql procedure to My-sql Procedure
By kriss in forum New To JavaReplies: 0Last Post: 02-03-2010, 08:20 AM -
stored procedure
By sankarigopi in forum JDBCReplies: 1Last Post: 11-13-2008, 04:53 PM -
My thread will not start
By markyoung1984 in forum Threads and SynchronizationReplies: 4Last Post: 10-03-2008, 06:32 PM -
OutOfMemoryError: Unable to Start New Native Thread
By edwin11 in forum Advanced JavaReplies: 0Last Post: 11-16-2007, 01:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks