Java线程池示例:定时器线程池

private static void newScheduledThreadPool() {
        ScheduledExecutorService service = Executors.newScheduledThreadPool(4);
        service.scheduleWithFixedDelay(()->{
            try {
                TimeUnit.MILLISECONDS.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName());
        },0,500,TimeUnit.MILLISECONDS);
    }

Java线程池示例:定时器线程池_第1张图片

你可能感兴趣的:(并发编程)