您好,登錄后才能下訂單哦!
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。