import java.util.*;
public class TestSleep
{
public static void main(String[] args)
{
Run r = new Run();
Thread t = new Thread(r);
t.start();
try{Thread.sleep(10000);}
catch(InterruptedException e){
t.interrupt();
}
}
}
class Run implements Runnable
{
boolean flag = true;
public void run(){
while(flag){
try{Thread.sleep(1000);}catch(InterruptedException e){return ;}
System.out.println("------"+ new Date()+ "-----");
}
}
}
public class TestSleep
{
public static void main(String[] args)
{
Run r = new Run();
Thread t = new Thread(r);
t.start();
try{Thread.sleep(10000);}
catch(InterruptedException e){
t.interrupt();
}
}
}
class Run implements Runnable
{
boolean flag = true;
public void run(){
while(flag){
try{Thread.sleep(1000);}catch(InterruptedException e){return ;}
System.out.println("------"+ new Date()+ "-----");
}
}
}
public class TestInterrupt {
public static void main(String[] args) {
MyThread thread = new MyThread();
thread.start();
try {Thread.sleep(10000);}
catch (InterruptedException e) {}
thread.interrupt();
}
}class MyThread extends Thread {
boolean flag = true;
public void run(){
while(flag){
System.out.println("==="+new Date()+"===");
try {
sleep(1000);
} catch (InterruptedException e) {
return;
}
}
}
}
那这个为什么在括号里可以实现那? 求大神详细解答下啊