Java多线程不共享数据

import org.omg.CORBA.PUBLIC_MEMBER;

/**
 * Created by wuyupku on 2019-04-12 12:24
 *
 * @Beijing CHINA
 */
public class Demo01 {
    public static void main(String[] args) {
        mythread thread1 = new mythread("a");
        mythread thread2 = new mythread("b");
        mythread thread3 = new mythread("c");
        mythread thread4 = new mythread("d");
        thread1.start();
        thread2.start();
        thread3.start();
        thread4.start();
        System.out.println("运行结束");
    }
}
class mythread extends Thread {
    private int count = 5;

    public mythread(String name) {
        super();
        this.setName(name);
    }

    @Override
    public void run() {
        super.run();
        while (count > 0) {
            count--;
            System.out.println("由" + this.currentThread().getName() + "计算,count" + count);
        }
    }
}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43258908/article/details/89234890
今日推荐