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

Java多线程(1)

时间:2021-04-13 12:09:53      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:exce   who   thread   线程   run   oid   class   每日   except   

我回来了,兄弟们,以后稳定每日一更哈。废话不多说,直接上码。

 1 class MyThread extends Thread {
 2     private String who;
 3     public MyThread(String str) {
 4         who=str;
 5     }
 6     public void run() {   //线程执行体   
 7         for(int i=0;i<=5;i++) {
 8             try {
 9                 sleep((int)(1000*Math.random()));
10             }
11             catch(InterruptedException e) {
12                 System.out.println(e.toString());
13             }
14             System.out.println(who+"正在运行!!");
15         }
16     }
17 }
18 public class Test {
19 
20     public static void main(String[] args) {
21 
22         MyThread you=new MyThread("你");
23         MyThread she=new MyThread("她");
24         you.start();
25         she.start();
26         System.out.println("主方法main()运行结束");
27         
28     }
29 
30 }

还是老规矩,难度依次上升。有什么不足之处下方评论,你的支持,是我更新最大的动力。

Java多线程(1)

标签:exce   who   thread   线程   run   oid   class   每日   except   

原文地址:https://www.cnblogs.com/ljydbk/p/14648544.html

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