日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Javadeadlock生成需要使用者注意源代碼

Java deadlock生成需要我們注意的關(guān)鍵點有很多,其實有不少的問題都能在源代碼中尋找到不少的答案。下面我們就看看如何才能更好的做出Java deadlock生成。希望大家有所收獲。

創(chuàng)新互聯(lián)是一家以重慶網(wǎng)站建設(shè)公司、網(wǎng)頁設(shè)計、品牌設(shè)計、軟件運維、seo優(yōu)化排名、小程序App開發(fā)等移動開發(fā)為一體互聯(lián)網(wǎng)公司。已累計為成都除甲醛等眾行業(yè)中小客戶提供優(yōu)質(zhì)的互聯(lián)網(wǎng)建站和軟件開發(fā)服務(wù)。

 
 
 
  1. public class Deadlock extends Object ...{  
  2. private String objID;  
  3. public Deadlock(String id) ...{  
  4. objID = id;  
  5. }  
  6. public synchronized void checkOther(Deadlock other) ...{  
  7. print("entering checkOther()");  
  8. // simulate some lengthy process  
  9. try ...{  
  10. Thread.sleep(2000);  
  11. } catch (InterruptedException x) ...{  
  12. }  
  13. print("in checkOther() - about to " + "invoke 'other.action()'");  
  14. other.action();  
  15. print("leaving checkOther()");  
  16. }  
  17. public synchronized void action() ...{  
  18. print("entering action()");  
  19. // simulate some work here  
  20. try ...{  
  21. Thread.sleep(500);  
  22. } catch (InterruptedException x) ...{  
  23. }  
  24. print("leaving action()");  
  25. }  
  26. public void print(String msg) ...{  
  27. threadPrint("objID=" + objID + " - " + msg);  
  28. }  
  29. public static void threadPrint(String msg) ...{  
  30. String threadName = Thread.currentThread().getName();  
  31. System.out.println(threadName + ": " + msg);  
  32. }  
  33. public static void main(String[] args) ...{  
  34. final Deadlock obj1 = new Deadlock("obj1");  
  35. final Deadlock obj2 = new Deadlock("obj2");  
  36. Runnable runA = new Runnable() ...{  
  37. public void run() ...{  
  38. obj1.checkOther(obj2);  
  39. }  
  40. };  
  41. Thread threadA = new Thread(runA, "threadA");  
  42. threadA.start();  
  43. try ...{  
  44. Thread.sleep(200);  
  45. } catch (InterruptedException x) ...{  
  46. }  
  47. Runnable runB = new Runnable() ...{  
  48. public void run() ...{  
  49. obj2.checkOther(obj1);  
  50. }  
  51. };  
  52. Thread threadB = new Thread(runB, "threadB");  
  53. threadB.start();  
  54. try ...{  
  55. Thread.sleep(5000);  
  56. } catch (InterruptedException x) ...{  
  57. }  
  58. threadPrint("finished sleeping");  
  59. threadPrint("about to interrupt() threadA");  
  60. threadA.interrupt();  
  61. try ...{  
  62. Thread.sleep(1000);  
  63. } catch (InterruptedException x) ...{  
  64. }  
  65. threadPrint("about to interrupt() threadB");  
  66. threadB.interrupt();  
  67. try ...{  
  68. Thread.sleep(1000);  
  69. } catch (InterruptedException x) ...{  
  70. }  
  71. threadPrint("did that break the deadlock?");  
  72. }  

以上就是對Java deadlock生成的詳細介紹,希望大家能有所領(lǐng)悟。

【編輯推薦】

  1. Java多線程中wait語句的具體使用方法
  2. Java多線程如何防止主線的阻塞
  3. Java多線程中Message類和Queue類的使用方法
  4. Java多線程程序如何掌握基本語法
  5. Java多線程應(yīng)用方法全解密

當(dāng)前名稱:Javadeadlock生成需要使用者注意源代碼
文章起源:http://www.5511xx.com/article/dhcepsi.html