package chapter1;
public class TestTwo {
public static void main(String[] args) throws InterruptedException {
MyThread thread1 = new MyThread("线程1");
MyThread thread2 = new MyThread("线程2");
// thread1.setPriority(1);
// thread2.setPriority(10);
// thread1.setName("555");
thread1.start();
Thread.sleep(2);
thread1.interrupt();
thread2.start();
// thread1.setPriority(1);
// System.out.println(thread1.getPriority());
// thread1.start();
// int j = 0;
// for (int i = 0; i < 100000; i++) {
// j+=i;
// }
// System.out.println("Main"+System.currentTimeMillis());
}
}
package chapter1;
public class MyThread extends Thread{
public MyThread(String name){
super(name);
}
@Override
public void run() {
for (int i = 0; i < 100; i++) {
if (isInterrupted()){
System.out.println("The ThreadOne is interrupted.");
break;
}
System.out.println(getName()+": "+i);
}
}
}