成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

Javadeadlock生成的示例分析

Java deadlock生成的示例分析,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。

創(chuàng)新互聯(lián)主要從事成都做網(wǎng)站、成都網(wǎng)站設(shè)計、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)岫巖,10年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18982081108

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

public class Deadlock extends Object ...{  private String objID;  public Deadlock(String id) ...{  objID = id;  }  public synchronized void checkOther(Deadlock other) ...{  print("entering checkOther()");  // simulate some lengthy process  try ...{  Thread.sleep(2000);  } catch (InterruptedException x) ...{  }  print("in checkOther() - about to " + "invoke 'other.action()'");  other.action();  print("leaving checkOther()");  }  public synchronized void action() ...{  print("entering action()");  // simulate some work here  try ...{  Thread.sleep(500);  } catch (InterruptedException x) ...{  }  print("leaving action()");  }  public void print(String msg) ...{  threadPrint("objID=" + objID + " - " + msg);  }  public static void threadPrint(String msg) ...{  String threadName = Thread.currentThread().getName();  System.out.println(threadName + ": " + msg);  }  public static void main(String[] args) ...{  final Deadlock obj1 = new Deadlock("obj1");  final Deadlock obj2 = new Deadlock("obj2");  Runnable runA = new Runnable() ...{  public void run() ...{  obj1.checkOther(obj2);  }  };  Thread threadA = new Thread(runA, "threadA");  threadA.start();  try ...{  Thread.sleep(200);  } catch (InterruptedException x) ...{  }  Runnable runB = new Runnable() ...{  public void run() ...{  obj2.checkOther(obj1);  }  };  Thread threadB = new Thread(runB, "threadB");  threadB.start();  try ...{  Thread.sleep(5000);  } catch (InterruptedException x) ...{  }  threadPrint("finished sleeping");  threadPrint("about to interrupt() threadA");  threadA.interrupt();  try ...{  Thread.sleep(1000);  } catch (InterruptedException x) ...{  }  threadPrint("about to interrupt() threadB");  threadB.interrupt();  try ...{  Thread.sleep(1000);  } catch (InterruptedException x) ...{  }  threadPrint("did that break the deadlock?");  }  }

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

看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進(jìn)一步的了解或閱讀更多相關(guān)文章,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對創(chuàng)新互聯(lián)的支持。

網(wǎng)站名稱:Javadeadlock生成的示例分析
標(biāo)題URL:http://jinyejixie.com/article48/ggggep.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計、響應(yīng)式網(wǎng)站、標(biāo)簽優(yōu)化外貿(mào)網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司
文昌市| 米易县| 澳门| 平定县| 乐至县| 沧州市| 乐陵市| 长丰县| 慈溪市| 冀州市| 天水市| 通海县| 博罗县| 怀远县| 昌都县| 天全县| 庆元县| 靖远县| 海兴县| 樟树市| 班玛县| 诸暨市| 丹寨县| 东城区| 海城市| 沁阳市| 龙州县| 仁怀市| 重庆市| 白沙| 乌拉特前旗| 金塔县| 皋兰县| 阿荣旗| 融水| 大荔县| 年辖:市辖区| 南郑县| 安阳市| 盐城市| 富源县|