package chapter1;publicclassTestTwo{publicstaticvoidmain(String[] args)throws InterruptedException {
MyThread thread1 =newMyThread("线程1");
MyThread thread2 =newMyThread("线程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;publicclassMyThreadextendsThread{publicMyThread(String name){super(name);}@Overridepublicvoidrun(){for(int i =0; i <100; i++){if(isInterrupted()){
System.out.println("The ThreadOne is interrupted.");break;}
System.out.println(getName()+": "+i);}}}