- package lm.thread;
- /*
- * 关于守護線程的演示,礼让程序
- */
- public class ThreadDemo9 {
- public static void main(String[] args) throws InterruptedException {
- Mythread10 th1 = new Mythread10();
- th1.setName("lm1");
- th1.start();
- }
- }
- class Mythread10 extends Thread {
- @Override
- public void run() {
- for (int i = 0; i < 10; i++) {
- try {
- System.out.println("我休眠第"+i+"次");
- Thread.sleep(100);
- } catch (InterruptedException e) {
- }
- if (i == 5) {
- Thread.currentThread().interrupt();
- System.out.println("我中断啦");
-
- } else {
- System.out.println(Thread.currentThread().getName() + "_" + i);
- }
- }
- }
- }
复制代码 |
|