码迷,mamicode.com
首页 > 编程语言 > 详细

java 多线程 3

时间:2017-01-22 07:55:00      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:end   ppi   main   []   thread   exception   dex   out   run   

 1 package com.imooc.base;
 2 
 3 public class WrongWayStopThread extends Thread {
 4 
 5     public static void main(String[] args) {
 6         WrongWayStopThread thread = new WrongWayStopThread();
 7         System.out.println("Starting thread...");
 8         thread.start();
 9         try {
10             Thread.sleep(3000);
11         } catch (InterruptedException e) {
12             e.printStackTrace();
13         }
14         System.out.println("Interrupting thread...");
15         thread.interrupt();
16         System.out.println("thread interrupted?"+thread.isInterrupted());
17         
18         try {
19             Thread.sleep(3000);
20         } catch (InterruptedException e) {
21             e.printStackTrace();
22         }
23         System.out.println("Stopping application...");
24     }
25     public void run(){
26         while(!this.isInterrupted()){
27             System.out.println("Thread is running...");
28 //            long time = System.currentTimeMillis();
29 //            while(System.currentTimeMillis()-time < 1000){
30 //                
31 //            }
32             try {
33                 Thread.sleep(3000);
34             } catch (InterruptedException e) {
35                 e.printStackTrace();
36             }
37             boolean flag = Thread.interrupted();
38             System.out.println(flag);
39         }
40     }
41 }

 

java 多线程 3

标签:end   ppi   main   []   thread   exception   dex   out   run   

原文地址:http://www.cnblogs.com/zhuzhuqwa/p/6338104.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!