美文网首页
countdown设计模式

countdown设计模式

作者: jiahzhon | 来源:发表于2020-10-13 17:03 被阅读0次
  • 使用JDK自带的countdownLatch
public class JDKCountDown {

    private static final Random random = new Random(System.currentTimeMillis());

    public static void main(String[] args) throws InterruptedException {

        final CountDownLatch latch = new CountDownLatch(5);
        System.out.println("准备多线程处理任务.");
        //The first phase.

        IntStream.rangeClosed(1, 5).forEach(i ->
                new Thread(() -> {
                    System.out.println(Thread.currentThread().getName() + " is working.");
                    try {
                        Thread.sleep(random.nextInt(1000));
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    latch.countDown();
                }, String.valueOf(i)).start()
        );

        latch.await();
        //The second phase.
        System.out.println("多线程任务全部结束,准备第二阶段任务");
        System.out.println("............");
        System.out.println("FINISH");

    }
}

相关文章

  • countdown设计模式

    使用JDK自带的countdownLatch

  • react常用的倒计时组件

    React Countdown Clock安装 npm install react-countdown-clo...

  • countdown

    tomorrow is the first day of postgraduate entrance examin...

  • Countdown

    Night is dark, Mind is blank, Couldn’t see a thing. Clock...

  • Countdown

    运行效果:

  • react强制更新hooks组件

    需求:countdown改变,更新CountDown组件 解决方案:通过countDownVisible控制组件是...

  • CountDownLatch

    Constructor countDown await

  • 设计模式

    常用的设计模式有,单例设计模式、观察者设计模式、工厂设计模式、装饰设计模式、代理设计模式,模板设计模式等等。 单例...

  • 设计模式笔记汇总

    目录 设计原则 “依赖倒置”原则 未完待续... 设计模式 设计模式——策略模式 设计模式——装饰者模式 设计模式...

  • 设计模式

    《C#设计模式》 《C#设计模式》-设计模式概述 《C#设计模式》-面向对象设计原则 《C#设计模式》-单例模式 ...

网友评论

      本文标题:countdown设计模式

      本文链接:https://www.haomeiwen.com/subject/bryxpktx.html