import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class ScheduleAtFixedRateDemo {
public static void main(String[] args) {
ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
SimpleDateFormat df =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
executorService.scheduleAtFixedRate(new Runnable(){
@Override
public void run() {
System.out.println("++++++++++++++++++++thread:" + df.format(new Date()));
}
}, 2, 3, TimeUnit.SECONDS);
System.out.println("++++++++++++++++++++main:" + df.format(new Date()));
}
}
++++++++++++++++++++main:2017-10-20 15:20:52 ++++++++++++++++++++thread:2017-10-20 15:20:54 ++++++++++++++++++++thread:2017-10-20 15:20:57 ++++++++++++++++++++thread:2017-10-20 15:21:00 ++++++++++++++++++++thread:2017-10-20 15:21:03 ++++++++++++++++++++thread:2017-10-20 15:21:06
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* ScheduleWithFixedDelay的用法
* @author Administrator
*
*/
public class ScheduleWithFixedDelayDemo {
public static void main(String[] args) {
ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
SimpleDateFormat df =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
executorService.scheduleWithFixedDelay(new Runnable(){
@Override
public void run() {
System.out.println("++++++++++++++++++++thread:" + df.format(new Date()));
}
}, 2, 3, TimeUnit.SECONDS);
System.out.println("++++++++++++++++++++main:" + df.format(new Date()));
}
}
++++++++++++++++++++main:2017-10-20 15:24:32 ++++++++++++++++++++thread:2017-10-20 15:24:34 ++++++++++++++++++++thread:2017-10-20 15:24:37 ++++++++++++++++++++thread:2017-10-20 15:24:40 ++++++++++++++++++++thread:2017-10-20 15:24:43
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有