日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

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

新聞中心

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

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

創(chuàng)新互聯(lián)是一家以重慶網(wǎng)站建設(shè)公司、網(wǎng)頁(yè)設(shè)計(jì)、品牌設(shè)計(jì)、軟件運(yùn)維、seo優(yōu)化排名、小程序App開發(fā)等移動(dòng)開發(fā)為一體互聯(lián)網(wǎng)公司。已累計(jì)為成都除甲醛等眾行業(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. }  

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

【編輯推薦】

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

網(wǎng)頁(yè)名稱:Javadeadlock生成需要使用者注意源代碼
文章來(lái)源:http://www.dlmjj.cn/article/dhcepsi.html