privatevoidtest(){newThread(){publicvoidrun(){while(true){try{Thread.sleep(4000);}catch(InterruptedExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}if(issto...
private void test(){
new Thread(){
public void run() {
while(true){
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(isstop){
break;
}
i++;
System.out.println("hello");
}
};
}.start();
}
当用户点暂停的时候 isstop=true;
这样就可以了,但是有个问题,在线程执行的4s内,如果用户多次点启动线程,这样就会同时运行多个一样的线程,但只需要一个线程就可以了,不知怎么搞,难啊,帮看看
线程里做的是循环的操作 用户可以暂停循环 之后可以再次启动 循环内容可以打印字符串
展开