ScheduledThreadPoolExecutor 关于 s

2017-02-28  本文已影响0人  Unixtrong
final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
executor.schedule(new Runnable() {
    @Override
    public void run() {
        System.out.println("+++ executor run.");
    }
}, 5, TimeUnit.SECONDS);
new Thread(new Runnable() {
    @Override
    public void run() {
        HCTools.sleep(1, TimeUnit.SECONDS);
        executor.shutdown();
        System.out.println("--- executor shutdown.");
    }
}).start();

输出结果:

--- executor shutdown.
+++ executor run.
final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
executor.schedule(new Runnable() {
    @Override
    public void run() {
        System.out.println("+++ executor run.");
    }
}, 5, TimeUnit.SECONDS);
new Thread(new Runnable() {
    @Override
    public void run() {
        HCTools.sleep(1, TimeUnit.SECONDS);
        executor.shutdownNow();
        System.out.println("--- executor shutdownNow.");
    }
}).start();

输出结果:

--- executor shutdownNow.
上一篇下一篇

猜你喜欢

热点阅读