threadterminatebyflag.java
来自「java程序设计源代码」· Java 代码 · 共 33 行
JAVA
33 行
import java.util.*;
public class ThreadTerminateByFlag {
public static void main(String args[]) {
Timer timer = new Timer();
Thread thread = new Thread( timer );
thread.setName( "Timer" );
thread.start();
for( int i=0; i<100; i++ ){
System.out.print("\r" + i );
try{
Thread.sleep(100);
}catch( InterruptedException e ){}
}
timer.stopRun();
}
}
class Timer implements Runnable {
boolean flg = true;
public void run() {
while(flg){
System.out.print( "\r\t" + new Date() + "..." );
try{
Thread.sleep(1000);
}catch( InterruptedException e ){}
}
System.out.println( "\n" + Thread.currentThread().getName() + " Stop" );
}
public void stopRun(){
flg = false;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?