package com.skcc.mthread;
public class MyThread001 extends Thread {
private int count=4;
public MyThread001() {
// TODO Auto-generated constructor stub
}
@Override
public synchronized void run() {
count--;
System.out.println(Thread.currentThread().getName() + " = " + count);
}
/***
* 多个线程同时竞争MyThread001类实例对象及成员方法
* 多个线程按照CPU分配时间顺序来执行,(t1到t4的执行顺序需参考CPU分配的顺序来定)
*
* ****/
public static void main(String[] args) {
// TODO Auto-generated method stub
MyThread001 myThread = new MyThread001();
Thread t1 = new Thread(myThread,"t1");
Thread t2 = new Thread(myThread,"t2");
Thread t3 = new Thread(myThread,"t3");
Thread t4 = new Thread(myThread,"t4");
t1.start();
t2.start();
t3.start();
t4.start();
}
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。