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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Java多線程中Message類和Queue類的使用方法

在Java多線程的應(yīng)用中有狠多需要我們主要的事情,其中以Message類和Queue類最為重要。在使用的時候我們需要不斷的學(xué)習(xí)相關(guān)的知識,這樣才能熟練的掌握在Java多線程中相關(guān)的使用方法。

站在用戶的角度思考問題,與客戶深入溝通,找到平川網(wǎng)站設(shè)計與平川網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、國際域名空間、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋平川地區(qū)。

Message類

 
 
 
  1. package com.example.test;  
  2. public class Message {  
  3. public static int id;  
  4. public String content;  
  5. public String getContent() {  
  6. return content;  
  7. }  
  8. public void setContent(String content) {  
  9. this.content = content;  
  10. }  
  11. public int getId() {  
  12. return id;  
  13. }  
  14. public void setId(int id) {  
  15. Message.id = id;  
  16. }  

 

Queue類

 
 
 
  1. package com.example.test;  
  2. import java.util.ArrayList;  
  3. import java.util.List;  
  4. public class Queue {  
  5. List queue = new ArrayList();  
  6. /** 隊列中message對象的***值,默認為5 */  
  7. int maxMessageNum = 5;  
  8. public synchronized void produce(Message message) {  
  9. this.notifyAll();  
  10. while (queue.size() == maxMessageNum) {  
  11. System.out.println(Thread.currentThread().getName()  
  12. + " 隊列滿!等待中。");  
  13. try {  
  14. this.wait();  
  15. } catch (InterruptedException e) {  
  16. e.printStackTrace();  
  17. }  
  18. }  
  19. queue.add(message);  
  20. System.out.println(Thread.currentThread().getName() + "正在生產(chǎn)"  
  21. + message.getContent() + "。 ,當(dāng)前個數(shù):" + getCount());  
  22. }  
  23. public synchronized void consume() {  
  24. this.notifyAll();  
  25. while (queue.size() == 0) {  
  26. System.out.println(Thread.currentThread().getName()  
  27. + " 隊列空!等待中。");  
  28. try {  
  29. System.out.println("begin!");  
  30. wait();  
  31. System.out.println("end!");  
  32. } catch (InterruptedException e) {  
  33. e.printStackTrace();  
  34. }  
  35. }  
  36. Message message = queue.get(0);  
  37. queue.remove(0);  
  38. System.out.println(Thread.currentThread().getName() + "正在消費"  
  39. + message.getContent() + "。 ,當(dāng)前個數(shù): " + getCount());  
  40. }  
  41. public synchronized int getCount() {  
  42. return queue.size(); 

以上就是對Java多線程的詳細介紹。相關(guān)的問題我們還是會不斷的向大家介紹。


分享標(biāo)題:Java多線程中Message類和Queue類的使用方法
URL網(wǎng)址:http://m.5511xx.com/article/ccssoje.html