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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Java多線程循環(huán)相關的代碼介紹

Java多線程循環(huán)需要我們不斷的學習,有很多的問題一直是我們相互關心的。下面我們就來看看如何才能更好的使用這門編程語言。當每個迭代彼此獨立,并且完成循環(huán)體中每個迭代的工作,意義都足夠重大,足以彌補管理一個新任務的開銷時,這個順序循環(huán)是適合并行化的。

成都創(chuàng)新互聯(lián)公司專注于臨武網(wǎng)站建設服務及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供臨武營銷型網(wǎng)站建設,臨武網(wǎng)站制作、臨武網(wǎng)頁設計、臨武網(wǎng)站官網(wǎng)定制、成都微信小程序服務,打造臨武網(wǎng)絡公司原創(chuàng)品牌,更為您提供臨武網(wǎng)站排名全網(wǎng)營銷落地服務。

 
 
 
  1. public voidParallelRecursive(final Executorexec,
    List>nodes,Collection results){  
  2. for(Node n:nodes){  
  3. exec.execute(new Runnable(){  
  4. public void run(){  
  5. results.add(n.compute());  
  6. }  
  7. });  
  8. parallelRecursive(exec,n.getChildren(),results);  
  9. }  
  10. }  
  11. publicCollectiongetParallelResults(List>nodes)  
  12. throws InterruptedException{  
  13. ExecutorService exec=Executors.newCachedThreadPool();  
  14. Queue resultQueue=newConcurrentLinkedQueue();  
  15. parallelRecursive(exec,nodes,resultQueue);  
  16. exec.shutdown();  
  17. exec.awaitTermination(Long.MAX_VALUE,TimeUnit.SECONDS);  
  18. return reslutQueue;  

但是以上程序不能處理不存在任何方案的情況,而下列程序可以解決這個問題

 
 
 
  1. public class PuzzleSolverextendsConcurrent
    PuzzleSolver{  
  2. ...  
  3. privatefinal AtomicInteger taskCount=new AtomicInteger(0);  
  4. protectedRunnable newTask(P p,M m,Noden){  
  5. return new CountingSolverTask(p,m,n);  
  6. }  
  7. classCountingSolverTask extends SolverTask{  
  8. CountingSolverTask(P pos,Mmove,Node prev){  
  9. super(pos,move,prev);  
  10. taskCount.incrementAndGet();  
  11. }  
  12. publicvoid run(){  
  13. try{  
  14. super.run();  
  15. }  
  16. finally{  
  17. if (taskCount.decrementAndGet()==0)  
  18. solution.setValue(null);  
  19. }  
  20. }  
  21. }  

以上就是對Java多線程循環(huán)的相關介紹。希望大家有所收獲。


網(wǎng)頁標題:Java多線程循環(huán)相關的代碼介紹
當前路徑:http://www.5511xx.com/article/coijded.html