日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

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

新聞中心

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

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

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

 
 
 
  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;  

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

 
 
 
  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. }  

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


本文標(biāo)題:Java多線程循環(huán)相關(guān)的代碼介紹
網(wǎng)站網(wǎng)址:http://www.dlmjj.cn/article/coijded.html