ScheduledThreadPoolDemo01
Posted tonggc1668
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ScheduledThreadPoolDemo01相关的知识,希望对你有一定的参考价值。
package com.zhy.concurrency.timer; import java.util.Date; import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; public class ScheduledThreadPoolDemo01 { public static void main(String[] args) throws InterruptedException { final TimerTask task1 = new TimerTask() { @Override public void run() { throw new RuntimeException(); } }; final TimerTask task2 = new TimerTask() { @Override public void run() { System.out.println("task2 invoked!"); } }; ScheduledExecutorService pool = Executors.newScheduledThreadPool(1); pool.schedule(task1, 100, TimeUnit.MILLISECONDS); pool.scheduleAtFixedRate(task2, 0 , 1000, TimeUnit.MILLISECONDS); } }
以上是关于ScheduledThreadPoolDemo01的主要内容,如果未能解决你的问题,请参考以下文章
01.01教程简介01.02软件的基本工作界面01.03模型设计的一般过程