首页 > 代码库 > java笔记线程方式1睡眠

java笔记线程方式1睡眠

技术分享
 1 public class ThreadSleepDemo {
 2     public static void main(String[] args) {
 3         ThreadSleep ts1 = new ThreadSleep();
 4         ThreadSleep ts2 = new ThreadSleep();
 5         ThreadSleep ts3 = new ThreadSleep();
 6 
 7         ts1.setName("林青霞");
 8         ts2.setName("林志玲");
 9         ts3.setName("林志颖");
10 
11         ts1.start();
12         ts2.start();
13         ts3.start();
14     }
15 }
16 
17 public class ThreadSleep extends Thread {
18     @Override
19     public void run() {
20         for (int x = 0; x < 100; x++) {
21             System.out.println(getName() + ":" + x + ",日期:" + new Date());
22             // 睡眠
23             // 困了,我稍微休息1秒钟
24             try {
25                 Thread.sleep(1000);
26             } catch (InterruptedException e) {
27                 e.printStackTrace();
28             }
29         }
30     }
31 }
View Code

 

java笔记线程方式1睡眠