public static void main(String[] args) throws Exception {
System.out.println("话说一天许仙被法海抓了");
Thread th = new Thread(new Runnable() {
@Override
public void run() {
for(int i = 0;i < 10; i++){
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName()+"说:娘子救我!!");
}
}
});
th.setName("许仙");
th.start();
new Thread(new Runnable() {
@Override
public void run() {
Thread.currentThread().setName("白娘子");
for(int i = 0;i < 10; i++){
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName()+"说:官人我来了!");
}
}
}).start();
for (int i = 0; i < 10; i++) {
Thread.sleep(500);
Thread.currentThread().setName("法海");
System.out.println(Thread.currentThread().getName()+"说:人与妖不能在一起!!");
}