Java教程

多线程运行图解

本文主要是介绍多线程运行图解,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
 1 package multithread;
 2 
 3 class Demo extends Thread{
 4     private String name;
 5     Demo(String name){
 6         this.name=name;
 7     }
 8     public void run() {
 9         int[] arr = new int[3];
10         System.out.println(arr[3]);
11         for (int x = 0; x < 10; x++) {
12             System.out.println("....x="+x+"....name="+Thread.currentThread());
13         }
14     }
15 }
16 
17 public class ThreadDemo3 {
18 
19     public static void main(String[] args) {
20         // TODO Auto-generated method stub
21         Demo d1 = new Demo("旺财");
22         Demo d2 = new Demo("xiaoqiang");
23         d1.start();
24         d2.start();
25         
26         System.out.println(4/0);//throw new ArithmeticException
27         for (int x = 0; x < 20; x++) {
28             System.out.println(x+"...."+Thread.currentThread().getName());
29         }
30     }
31 
32 }
ThreadDemo3

 

这篇关于多线程运行图解的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!