女人荫蒂被添全过程13种图片,亚洲+欧美+在线,欧洲精品无码一区二区三区 ,在厨房拨开内裤进入毛片

您好,歡迎來電子發(fā)燒友網(wǎng)! ,新用戶?[免費(fèi)注冊]

您的位置:電子發(fā)燒友網(wǎng)>源碼下載>java源碼下載>

分析在java中sleep和wait的不同

大小:1.5 MB 人氣: 2017-09-27 需要積分:2

  對于sleep()方法,我們首先要知道該方法是屬于Thread類中的。而wait()方法,則是屬于Object類中的。

  sleep()方法導(dǎo)致了程序暫停執(zhí)行指定的時(shí)間,讓出cpu該其他線程,但是他的監(jiān)控狀態(tài)依然保持者,當(dāng)指定的時(shí)間到了又會自動(dòng)恢復(fù)運(yùn)行狀態(tài)。

  在調(diào)用sleep()方法的過程中,線程不會釋放對象鎖。

  而當(dāng)調(diào)用wait()方法的時(shí)候,線程會放棄對象鎖,進(jìn)入等待此對象的等待鎖定池,只有針對此對象調(diào)用notify()方法后本線程才進(jìn)入對象鎖定池準(zhǔn)備

  獲取對象鎖進(jìn)入運(yùn)行狀態(tài)。

  什么意思呢?

  舉個(gè)列子說明:

  /** * */packagecom.b510.test; /** * java中的sleep()和wait()的區(qū)別 *@authorHongten Java學(xué)習(xí)交流QQ群:589809992 我們一起學(xué)Java! *@date2013-12-10 */publicclassTestD{publicstaticvoidmain(String[] args) { newThread( newThread1()).start();try{ Thread.sleep( 5000); } catch(Exception e) { e.printStackTrace(); } newThread(newThread2()).start(); }privatestaticclassThread1implementsRunnable{@Overridepublicvoidrun(){synchronized(TestD.class) { System.out.println( “enter thread1.。。”); System.out.println(“thread1 is waiting.。。”); try{ //調(diào)用wait()方法,線程會放棄對象鎖,進(jìn)入等待此對象的等待鎖定池TestD.class.wait(); } catch(Exception e) { e.printStackTrace(); } System.out.println(“thread1 is going on 。。.。”); System.out.println( “thread1 is over!!!”); } } }privatestaticclassThread2implementsRunnable{@Overridepublicvoidrun(){synchronized(TestD.class) { System.out.println( “enter thread2.。。.”); System.out.println(“thread2 is sleep.。。.”); //只有針對此對象調(diào)用notify()方法后本線程才進(jìn)入對象鎖定池準(zhǔn)備獲取對象鎖進(jìn)入運(yùn)行狀態(tài)。TestD.class.notify(); //==================//區(qū)別//如果我們把代碼:TestD.class.notify();給注釋掉,即TestD.class調(diào)用了wait()方法,但是沒有調(diào)用notify()//方法,則線程永遠(yuǎn)處于掛起狀態(tài)。try{ //sleep()方法導(dǎo)致了程序暫停執(zhí)行指定的時(shí)間,讓出cpu該其他線程,//但是他的監(jiān)控狀態(tài)依然保持者,當(dāng)指定的時(shí)間到了又會自動(dòng)恢復(fù)運(yùn)行狀態(tài)。//在調(diào)用sleep()方法的過程中,線程不會釋放對象鎖。Thread.sleep( 5000); }catch(Exception e) { e.printStackTrace(); } System.out.println( “thread2 is going on.。。.”); System.out.println( “thread2 is over!!!”); } } } }

  運(yùn)行效果:

  enter thread1.。。 thread1 iswaiting.。。 enter thread2.。。. thread2 issleep.。。. thread2 isgoingon.。。. thread2 isover!!! thread1 isgoing on.。。. thread1 isover!!!

  如果注釋掉代碼:

  1TestD .class.notify() ;

  運(yùn)行效果:

  enter thread1.。。 thread1 iswaiting.。。 enter thread2.。。. thread2 issleep.。。. thread2 isgoingon.。。. thread2 isover!!!

  且程序一直處于掛起狀態(tài)。返回

非常好我支持^.^

(0) 0%

不好我反對

(0) 0%

      發(fā)表評論

      用戶評論
      評價(jià):好評中評差評

      發(fā)表評論,獲取積分! 請遵守相關(guān)規(guī)定!

      ?
      主站蜘蛛池模板: 闸北区| 鹤山市| 永登县| 共和县| 商南县| 裕民县| 延寿县| 乌拉特中旗| 丹江口市| 镇远县| 阿城市| 鱼台县| 天全县| 炎陵县| 贡山| 宝清县| 平顶山市| 宝应县| 龙岩市| 泾阳县| 阳城县| 东至县| 昭觉县| 平利县| 常德市| 北宁市| 庐江县| 抚顺县| 历史| 永登县| 宁阳县| 论坛| 临城县| 黄陵县| 施甸县| 囊谦县| 武山县| 石屏县| 宝兴县| 堆龙德庆县| 龙口市|