91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 2.64KB
    文件類型: .zip
    金幣: 1
    下載: 0 次
    發布日期: 2021-02-20
  • 語言: Java
  • 標簽:

資源簡介

Java 簡單的線程死鎖(基礎篇-實例180).zip

資源截圖

代碼片段和文件信息

package?com.mingrisoft.thread;

public?class?DeadLock?implements?Runnable?{
????private?boolean?flag;//?使用flag變量作為進入不同塊的標志
????private?static?final?object?o1?=?new?object();
????private?static?final?object?o2?=?new?object();
????
????public?void?run()?{
????????String?threadName?=?Thread.currentThread().getName();//?獲得當前線程的名字
????????System.out.println(threadName?+?“:?flag?=?“?+?flag);//?輸出當前線程的flag變量值
????????if?(flag?==?true)?{
????????????synchronized?(o1)?{//?為o1加鎖
????????????????try?{
????????????????????Thread.sleep(1000);//?線程休眠1秒鐘
????????????????}?catch?(InterruptedException?e)?{
????????????????????e.printStackTrace();
????????????????}
????????????????System.out.println(threadName?+?“進入同步塊o1準備進入o2“);//?顯示進入o1塊
????????????????synchronized?(o2)?{//?為o2加鎖
????????????????????System.out.println(threadName?+?“已經進入同步塊o2“);//?顯示進入o2塊
????????????????}
????????????}
????????}
????????if?(flag?==?false)?{
????????????synchronized?(o2)?{
????????????????try?

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????232??2015-08-28?13:54??.classpath
?????文件?????????379??2015-08-28?13:54??.project
?????文件????????2241??2015-08-28?13:54??bin\com\mingrisoft\thread\DeadLock.class
?????文件????????1905??2015-08-28?13:54??src\com\mingrisoft\thread\DeadLock.java

評論

共有 條評論