public static void main(String[] args) {
Runner1 r1 = new Runner1();
Thread t = new Thread(r1);
t.start();
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
t.interrupt();
System.out.println("子线程结束");
}
class Runner1 implements Runnable{
boolean flag = true;
@Override
public void run() {
while(flag){
System.out.println("---"+new Date()+"---");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
flag = false;
}
}
}
}
时间: 2025-01-05 14:23:44