Article View: borland.public.jbuilder.java.api
Article #174Why can I not restart a thread which had stopped?
From: jinxiaojin
Date: Sat, 24 Jul 2004 07:02
Date: Sat, 24 Jul 2004 07:02
52 lines
1861 bytes
1861 bytes
I wrote follow codes,and found this thread only run once
I hope this thread run twice,and i think the program will print:
Thread is running
Thread exit
Thread is running
Thread exit
In fact ,it is :
Thread is running
Thread exit
public class ThreadTest2 {
MyThread mythread;
/** Creates a new instance of ThreadTest2 */
public ThreadTest2() {
mythread = new MyThread();
test();
}
private void test() {
mythread.start();
try {
Thread.sleep(1000l);// mythread has finish his job
}
catch(Exception ex) {
ex.printStackTrace();
}
mythread.start();
}
/**
* test main method
*/
static public void main(String[] args) {
ThreadTest2 test = new ThreadTest2();
}
}
class MyThread extends Thread {
public MyThread() {
}
public void run() {
System.out.println("Thread is running");
System.out.println("Thread exit");
}
}
Technical Details
Message-ID:
<41020976$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news.zanker.org!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 1089d0,643a33a4ab191a18,start X-Google-Attributes: gid1089d0,public X-Google-Language: ENGLISH,ASCII-7-bit From: "jinxiaojin" <jinxiaojin@126.com> Sender: "jinxiaojin" <jinxiaojin@126.com> Reply-To: "jinxiaojin" <jinxiaojin@126.com> Subject: Why can I not restart a thread which had stopped? Newsgroups: borland.public.jbuilder.java.api X-User-Info: 210.21.223.20 NNTP-Posting-Host: 207.105.83.66 Message-ID: <41020976$1@newsgroups.borland.com> Date: 24 Jul 2004 00:02:14 -0700 X-Trace: newsgroups.borland.com 1090652534 207.105.83.66 (24 Jul 2004 00:02:14 -0700) Lines: 52 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news.zanker.org!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail