freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內容

java語言程序設計基礎第2版線程ppt-文庫吧資料

2024-10-24 15:05本頁面
  

【正文】 threadB)。 }catch ( InterruptedException x ) { } Runnable runB = new Runnable() { public void run() { (7)。 ()。 } }。 final TwoObjects obj2 = new TwoObjects(obj2)。 public TwoObjects(String objID) { = objID。 new Thread2().run()。 (y)。 public void run() { synchronized (lockObject) { x = 1。 (x)。 public void run() { synchronized (lockObject) { x =0。 } } } 2021/11/10 44 程序某次運行結果: 早上好! 0 早上好! 1 歡迎您! 0 歡迎您! 1 2021/11/10 45 線程同步 ?在 Java中 ,通過對象加鎖實現(xiàn)同步機制 .在 Java中 ,每個對象 (包括數(shù)組 )都有一把鎖 ,只在對某資源獲得其鎖時才能訪問該資源 .鎖實現(xiàn)了互斥功能 ,也就是保證在同一時間內 ,只有一個線程可訪問共享資源 . 對象鎖機制保證同步規(guī)則是 : ?線程在可以進入共享資源之前 ,必須先獲得該資源的對象鎖 .Java運行系統(tǒng)保證對某個資源已有線程控制其對象鎖時 ,其他線程就不能進入該資源 .如線程不能立即獲得資源的對象鎖 ,該線程必須在等到該鎖有空之前都被封鎖 . ?線程退出共享資源時 ,Java運行系統(tǒng)保證該資源的對象鎖空出來 .如有等待該資源對象鎖的線程 ,按次序可獲得該對象鎖 . 2021/11/10 46 簡單線程同步 public class SyncExample { private static Object lockObject = new Object()。 public void run( ){ while( true){ (歡迎您! +i++)。 //等待 t運行結束 } 2021/11/10 43 if (i==2) break 。 ()){ (等 Wele!)。 if (i == 2 amp。 ( )。 } } 2021/11/10 41 程序運行結果 : in run() – 休眠大概 20秒 in main() – 中斷其他線程 in run() – 中斷一忽兒休眠 in main() – 離開 2021/11/10 42 join()方法的使用 public class ThreadJoin{ public static void main(String args[ ]) throws Exception{ int i=0。 ()。 //讓新的線程獲得機會去執(zhí)行 try { (2021)。 Thread t = new Thread(si)。 (in run() 正常離開 )。 return。 (in run() 醒來 )。 } } 2021/11/10 37 程序運行結果 : in run() – 優(yōu)先級 =8,線程名 =threadA in run() – 優(yōu)先級 =7,線程名 =threadC in run() – 優(yōu)先級 =2,線程名 =threadB in run() – 優(yōu)先級 =8,線程名 =threadA in run() – 優(yōu)先級 =7,線程名 =threadC in run() – 優(yōu)先級 =2,線程名 =threadB in mian() – ()=3 in run() – 優(yōu)先級 =7,線程名 =threadC in run() – 優(yōu)先級 =3,線程名 =threadA in run() – 優(yōu)先級 =2,線程名 =threadB in run() – 優(yōu)先級 =7,線程名 =threadC in run() – 優(yōu)先級 =3,線程名 =threadA in run() – 優(yōu)先級 =2,線程名 =threadB in run() – 優(yōu)先級 =7,線程名 =threadC in run() – 優(yōu)先級 =3,線程名 =threadA in run() – 優(yōu)先級 =2,線程名 =threadB 2021/11/10 38 線程的基本方法 ? sleep() ? yield() ? join() ? interrupt( ) ? currentThread() ? isAlive() ? stop() ? suspend( )與 resume( ) 2021/11/10 39 線程中斷的控制 public class SleepInterrupt implements Runnable { public void run() { try { (in run() 休眠大概 20秒 )。 }catch ( InterruptedException x ) { } (3)。 ()。 2021/11/10 36 Thread threadD = new Thread(r, threadD)。 ()。 ()。 Thread threadB = new Thread(makeRunnable(), threadB)。 (8)。 return r。 2021/11/10 34 try { (2021)。 i++ ) { Thread t = ()。 } } 2021/11/10 32 程序運行結果 : in main() – ().getPriority()=5 in main() – ().getName()=main in run() – 優(yōu)先級 =5, 線程名 =threadA in run() – 優(yōu)先級 =5, 線程名 =threadA in main() – ()=5 in run() – 優(yōu)先級 =5, 線程名 =threadA in run() – 優(yōu)先級 =5, 線程名 =threadA in run() – 優(yōu)先級 =5, 線程名 =threadA 2021/11/10 33 設置線程優(yōu)先級 public class SetPriority extends Object { private static Runnable makeRunnable() { Runnable r = new Runnable() { public void run() { for ( int i = 0。 try { (3000)。 Thread threadA = new Thread(makeRunnable(), threadA)。 } 2021/11/10 31 public static void main(String[] args) { (in main() ().getPriority()= + ().getPriority())。 } catch ( InterruptedException x ) { // ignore } } } }。 (in run() 優(yōu)先級 = + () + , 線程名 = + ())。 i 5。 。 ? void setPriority(int newPriority)。一個線程的缺省優(yōu)先級是 5,即 。線程調度器按照線程的優(yōu)先級決定應調度哪些線程來執(zhí)行。通常提倡采用實現(xiàn) Runnable接口的方式。而實現(xiàn)Runnable接口的方法,將不影響 Java Thread類的體系,所以更加符合面向對象設計的思想。 ?實現(xiàn) Runnable接口的優(yōu)勢 ,符合面向對象設計的思想 .因為從 OO設計的角度, Thread類是虛擬 CPU的封裝,所以 Thread的子類應該是關于 CPU行為的類。 if (i==2) break 。 } } 2021/11/10 22 class Wele implements Runnable{ int i 。 ( )。 2021/11/
點擊復制文檔內容
教學課件相關推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1