毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> java技术 >> 正文

CountDownLatch循环语句只执行了一次 第2页

更新时间:2013-4-29:  来源:毕业论文

我自己的另一个代码,可以正常运行

Java code import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors;   public class CountDownLatchTest {     public static void main(String[] args) {         ExecutorService service = Executors.newCachedThreadPool();         final CountDownLatch startSignal = new CountDownLatch(1);         final CountDownLatch doneSignal = new CountDownLatch(3);                   for(int i=0;i<3;i++){             Runnable runnable = new Runnable() {                                   @Override                public void run() {                     try {                         System.out.println("线程"+Thread.currentThread().getName()+"正在准备");                         startSignal.await();                         System.out.println("线程"+Thread.currentThread().getName()+"开始运行");                         Thread.sleep((long) (Math.random() * 10000));                         doneSignal.countDown();                                                   System.out.println("线程"+Thread.currentThread().getName()+"已运行完");                                               } catch (InterruptedException e) {                         e.printStackTrace();                     }                                       }             };             service.execute(runnable);         }                   try {             Thread.sleep((long) (Math.random() * 10000));                 System.out.println("线程"+Thread.currentThread().getName()+"即将发出任务");                 startSignal.countDown();                 System.out.println("线程"+Thread.currentThread().getName()+"已发出任务,等待完成");                 doneSignal.await();                 System.out.println("所有任务都已完成");                 } catch (InterruptedException e) {                     e.printStackTrace();                 }     }       }

上一页  [1] [2] 

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。