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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
Java線(xiàn)程通信源代碼中的奧秘探究

Java線(xiàn)程通信在使用的時(shí)候需要我們不斷學(xué)習(xí),在學(xué)習(xí)的時(shí)候會(huì)有很多的問(wèn)題存在。其實(shí)我們?cè)谠创a中就能發(fā)現(xiàn)其中的奧秘。因?yàn)門(mén)hreadNum和ThreadChar都有對(duì)Objecto的引用,所以你wait和notify的時(shí)候都應(yīng)該同步,Java線(xiàn)程通信具體看如下:

 
 
 
  1. public class Test8 {  
  2. public static void main(String[] args){   
  3. Object o=new Object();   
  4. Thread n=new ThreadNum(o);   
  5. Thread c=new ThreadChar(o);   
  6. n.start();   
  7. c.start();   
  8. }   
  9. }   
  10. class ThreadNum extends Thread{   
  11. Object o;   
  12. public ThreadNum(Object o){   
  13. this.o=o;   
  14. }   
  15. public void run(){   
  16. for(int i=1;i<26;i++){   
  17. System.out.println(i);   
  18. System.out.println(++i);   
  19. try {   
  20. synchronized (this) {  
  21. this.wait();   
  22. }  
  23. } catch (InterruptedException e) {}   
  24. synchronized (this) {  
  25.  
  26. this.notify();   
  27. }  
  28. }   
  29. }   
  30. }   
  31. class ThreadChar extends Thread{   
  32. Object o;   
  33. public ThreadChar(Object o){   
  34. this.o=o;   
  35. }   
  36. public void run(){   
  37. for(char a='A';a<='Z';a++){   
  38. System.out.println(a);   
  39. synchronized (this) {  
  40.  
  41. this.notify();   
  42. }  
  43. try {   
  44. synchronized (this) {  
  45. this.wait();   
  46. }  
  47. } catch (InterruptedException e) {}   
  48. }   
  49. }   
  50. }  

以上就是對(duì)Java線(xiàn)程通信的詳細(xì)介紹。


標(biāo)題名稱(chēng):Java線(xiàn)程通信源代碼中的奧秘探究
標(biāo)題鏈接:http://m.5511xx.com/article/cohdigh.html