java高级---->Thread之ScheduledExecutorService的使用
ScheduledExecutorService的主要作用就是可以将定时任务与线程池功能结合使用。今天我们来学习一下ScheduledExecutorService的用法。我们都太渺小了,那么容易便湮没于各自的殊途。
ScheduledExecutorService的简单使用
一、使用scheduleAtFixedRate()方法实现周期性执行
public class ScheduledExecutorServiceTest {
public static void main(String[] args) {
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
System.out.println("run "+ System.currentTimeMillis());
}
}, 0, 100, TimeUnit.MILLISECONDS);
}
}
运行的结果如下:立刻执行,而且每隔100毫秒执行一次。
run
run
run
run
run
run
run
run
run
.......
二、ScheduledExecutorService使用Callable延迟运行
package com.linux.thread; import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*; public class CallableRun {
public static void main(String[] args) {
try {
List<Callable> callableList = new ArrayList<>();
callableList.add(new MyCallableA());
callableList.add(new MyCallableB());
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
ScheduledFuture futureA = executorService.schedule(callableList.get(0), 4L, TimeUnit.SECONDS);
ScheduledFuture futureB = executorService.schedule(callableList.get(1), 4L, TimeUnit.SECONDS); System.out.println(" X = " + System.currentTimeMillis());
System.out.println("返回值A:" + futureA.get());
System.out.println("返回值B:" + futureB.get());
System.out.println(" Y = " + System.currentTimeMillis()); executorService.shutdown();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
} static class MyCallableA implements Callable<String> {
@Override
public String call() throws Exception{
try {
System.out.println("callA begin " + Thread.currentThread().getName() + ", " + System.currentTimeMillis());
TimeUnit.SECONDS.sleep(3); // 休眠3秒
System.out.println("callA end " + Thread.currentThread().getName() + ", " + System.currentTimeMillis());
} catch (Exception e) {
e.printStackTrace();
}
return "returnA";
}
} static class MyCallableB implements Callable<String> {
@Override
public String call() throws Exception{
System.out.println("callB begin " + Thread.currentThread().getName() + ", " + System.currentTimeMillis());
System.out.println("callB end " + Thread.currentThread().getName() + ", " + System.currentTimeMillis());
return "returnB";
}
}
}
运行的结果如下:
aaarticlea/gif;base64,R0lGODlhUAHpAHcAACH5BAAsAQAAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAUAHpAKf4+Pjx8fHp6ens+uvh4eHp+OmhoaFoaWjAwMCqsamampqKiooAAADZ2dnJycmenp7p6b6+6elZWVmRX5HBy8BgYGBoocKAgoDV1dWHh4eSkpJxcnGwuK9Wo8ih1vTQ28/l5eW5wriTmJOxurF4eXjY5dh2eHbu8PC6urqaoZpvcW9Djbmo1OnI08gxMTHi7+FSnMPS3tGor6egpqDq1ahfkb7U4NM4ODjN2M0iIiJCi7MqKiqjw9bAyr/Y5NdtbW3UqHkRERF+gX63wLeRvug7g6zg7t+xsbFdqMmRX19Sn8jo9edLlLtNmcRBQUFyp8aFiYWoeXmje7ypqalFk8O+yL15qNRGkbtfeaigdbiiqaJ5X5Ha193s7vDovpHV6urb6NqNko2cwdXk8OM2fah3sM0ZGRnp9uhzrMq+kV9IkbYze6Xp6dSoeV/l6u1KSkp+uNLo6NPH0cZtpcarg8GRX3nNzc1fX3k/iLOab7RTU1Ofdbi4t7mujsGzm8LT6OiohLx5X1+SqdYMDAxKv0qReV+/v5J5X3mRtMpfeZGRZqyJXqaVbLDM18tbp8lfX5HH2ufe5epJlsAe/x6YnpdNmL83gKoe7x4koiqjwqPovqd5eaixicYwdqLd2d8toj8ezR6Vv5VA9kCDt4Ovkr+ri76hhLI8iK9CiK9FkLXg3uKRkV95p6c4xDh+2Lsz1TNUoMWof7+ec7dL7EsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAABv9AgHBILBqPyGSRoXgQG0oA9EiZRhGVaNFarGq/3K8WKyZ2AoECocwWHwwFIiU6P0YC3xC+XDfe20h9gEh6YhcFBRICAQILG4OQRgMCkUZ7WpeAEUSZlUSbngCdSSwhHB+iAAIjoZGZAhcQSbCySKO2YrRDCQ6cnrpCvK23R4kScYwQjwQHM45CBhMTBsEHA6BwHmsAIAMKWdze4EUwaJcYBXsNHgsDFkLol93fQgEQ7tAF2kIEDha3ASwUqFACTzwhCMztsYfvSLY1aAgM2HMQQEJzSBJYwyaNGoB+//LtOzJJwABRARyIAOCCQYAECYQcWLDggJAGCDKokGkgwRT/BQQExAQAVGiSUXtcEmiR6VLRF/VESNjzxqcQDStM3EIAYQEIAguGNOUklVhVKCcsJMBwwpdYJTh1yqRpEwBWrTytkhRgMlURRkNKngQwicjEAIMNPOiwTTHjo5be+q03xPG2hUIODx5B6VbaEgMOUKIsmTQxzUIyHBhaevJew3w3d86MZrARYwUWjRaie8gBBgzqboBAAsFVBgK2BRX2UWivI72H9Na9iARvwABEOAeQgdGiDHaRbyvAwEAAj0U6FPiA6vruABIYcPceALwRDeIBXEAgoIQE6diJIkFYRwxXnEzA1UWeedTglxwSH5jCQgUBjAOBORzw0xE/BShAZCABHaIgRAoOXDNiiaAUoRUaoFwUwEUPPICGReYYJwOKKMU4I4gKiAjAAgpQ4ECKRHC1wDYY1CjEAwNkiIaOt/AoYgCizUgjGsYBwGSGR/D44YY/BulADB/RoAAGSFywQQEXBAEAOwA=" alt="" />
三、使用scheduleWithFixedDelay()方法实现周期性执行
package com.linux.thread; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; public class RunMain {
public static void main(String[] args) {
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
System.out.println(" x = " + System.currentTimeMillis());
executorService.scheduleWithFixedDelay(new MyRunable(), 1, 2, TimeUnit.SECONDS);
System.out.println(" y = " + System.currentTimeMillis());
} static class MyRunable implements Runnable {
@Override
public void run() {
try {
System.out.println(" begin = " + System.currentTimeMillis() + ", name: " + Thread.currentThread().getName());
TimeUnit.SECONDS.sleep(4);
System.out.println(" end = " + System.currentTimeMillis() + ", name: " + Thread.currentThread().getName());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
运行的结果如下:
aaarticlea/gif;base64,R0lGODlhhAGMAHcAACH5BAAoAAAAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAhAGMAKf////s+uvy8vLp+Onh4eGhoaFoaGjAwMCbm5vm5uapsKjY2NiKiorBy8BZWVmHh4fJyclxcnGAgICwubCTmJPr7u+wuK92eHbN2MzU4NOZoJnY5Nh4enjQ28+4wbhvcW/R3dFWoslSn8hTnsNAirFCjbpmZmZJkrvk8OOgpqDb6No5gaqjxNeiqaLI08i5wrjT09OEiIRdqMng7t9/gn+ieLoyeqVGkLpJlsDi7+Ho9efAyr+gdbjH0ca6urqpqalxqslro8Ryp8ZLmMWor6eRlpHY5Ne2v7be5erp9uiqgcA2fahUm8Bbp8l+uNKec7eUa7CbwNK+yL2ohLyNkYxCiK8/irHu8PDs7vB3sM3k6eyIjIiPlI9ToMezm8JOmsZIkba/yb7g3uIwdqLNzc1Fj7R9gH1WoMOxicZ2r8xvqciRZqyRtMrH2ueJXqaedLehhLKYnpfa192ujsGdwtdyrNHn6+6qir2ab7Svkr9NmL+of7+Zu89dXV3d2d+4t7lFkLWVuc4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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IknnjjBl3aFlIFcaiigwHEGqAkfTUMq4SKQE3pQQHMnwsngiUOEOKIQXHqJi4oBsFjEnG+ZIBRZEfhSRgGuYVNFAeEsqQIDVyFgAgGYAUApG0uORsB8os73aQBLAsfGHCIckMKFALT66hubduqAAQnY1WoIFwqA3oQBNMoGACEcQEEHK5Dhiy8UVLSoEB98A0JJQpDwAAFiWYutEBqEc4ESp5qTRATGMuroBuFQUCztBM8WS8EHXkBamqRFhKvQvfjiC4Gh+T6hZ78AByzwwAQXzEQ98BmssBJBAAA7AA==" alt="" />
友情链接
- 可以参考博客:http://blog.csdn.net/cages/article/details/7300992
- 关于spring中的定时器:http://blog.csdn.net/tsyj810883979/article/details/8481621
java高级---->Thread之ScheduledExecutorService的使用的更多相关文章
- java高级---->Thread之ExecutorService的使用
今天我们通过实例来学习一下ExecutorService的用法.我徒然学会了抗拒热闹,却还来不及透悟真正的冷清. ExecutorService的简单实例 一.ExecutorService的简单使用 ...
- java高级---->Thread之Phaser的使用
Phaser提供了动态增parties计数,这点比CyclicBarrier类操作parties更加方便.它是jdk1.7新增的类,今天我们就来学习一下它的用法.尘埃落定之后,回忆别来挑拨. Phas ...
- java高级---->Thread之CompletionService的使用
CompletionService的功能是以异步的方式一边生产新的任务,一边处理已完成任务的结果,这样可以将执行任务与处理任务分离开来进行处理.今天我们通过实例来学习一下CompletionServi ...
- java高级---->Thread之CyclicBarrier的使用
CyclicBarrier是一个同步辅助类,它允许一组线程互相等待,直到到达某个公共屏障点 (common barrier point).今天我们就学习一下CyclicBarrier的用法. Cycl ...
- java高级---->Thread之BlockingQueue的使用
今天我们通过实例来学习一下BlockingQueue的用法.梦想,可以天花乱坠,理想,是我们一步一个脚印踩出来的坎坷道路. BlockingQueue的实例 官方文档上的对于BlockingQueue ...
- java高级---->Thread之Exchanger的使用
Exchanger可以在两个线程之间交换数据,只能是2个线程,他不支持更多的线程之间互换数据.今天我们就通过实例来学习一下Exchanger的用法. Exchanger的简单实例 Exchanger是 ...
- java高级---->Thread之FutureTask的使用
FutureTask类是Future 的一个实现,并实现了Runnable,所以可通过Excutor(线程池) 来执行,也可传递给Thread对象执行.今天我们通过实例来学习一下FutureTask的 ...
- java高级---->Thread之Condition的使用
Condition 将 Object 监视器方法(wait.notify 和 notifyAll)分解成截然不同的对象,以便通过将这些对象与任意 Lock 实现组合使用,为每个对象提供多个等待 set ...
- java高级---->Thread之CountDownLatch的使用
CountDownLatch是JDK 5+里面闭锁的一个实现,允许一个或者多个线程等待某个事件的发生.今天我们通过一些实例来学习一下它的用法. CountDownLatch的简单使用 CountDow ...
随机推荐
- mariadb 内存占用优化
本文由云+社区发表 作者:工程师小熊 摘要:我们在使用mariadb的时候发现有时候不能启动起来,在使用过程中mariadb占用的内存很大,在这里学习下mariadb与内存相关的配置项,对mariad ...
- IIS配置HTTPS
1,新建网站,选中类型为 https,然后更改SSL证书为你配置的SSL证书, 对于SSL证书的配置是这样的 点开第二步,然后点击 创建自签名证书 确定以后点开网站看到有个SSL, 双击进去,再选中 ...
- C#數據庫
一.連接數據庫 1.定義連接數據庫的字符串 string source = "server=(local); integrated security=SSPI; database=test& ...
- GITHup的使用
一个源码管理工具,由于不擅长敲GIt命令,还不太喜欢用英文版本的软件,所以想办法用中文版的图形工具步骤如下: 下载了GIT64位,安装,下载了TortoiseGit和TortoiseGit中文语言包, ...
- ubuntu所有php扩展php-7.0扩展列表
sudo apt-get install php7.0-bcmath sudo apt-get install php7.0-bz2 sudo apt-get install php7.0-calen ...
- Hibernate框架笔记01_环境搭建_API_CRUD
目录 1. Hibernate框架的概述 1.1 什么是框架 1.2 经典三层架构 1.3 Hibernate框架 2 Hibernate入门 2.1 下载Hibernate的开发包 2.2 创建项目 ...
- 大型网站架构演进(6)使用NoSQL和搜索引擎
随着网站业务越来越复杂,对数据存储和检索的需求也越来越复杂,网站需要采用一些非关系型数据库技术(即NoSQL)和非数据库查询技术如搜索引擎.NoSQL数据库一般使用MongoDb,搜索引擎一般使用El ...
- Spring框架基础(下)
log4J 导入log4J.jar 创建log4J.properties # Create a file called log4j.properties as shown below and plac ...
- 6-Redis 的持久化之 AOF
2017-01-01 16:42:13 该系列文章链接NoSQL 数据库简介Redis的安装及及一些杂项基础知识Redis 的常用五大数据类型(key,string,hash,list,set,zse ...
- CSS3图片翻转动画技术详解
CSS动画非常的有趣:这种技术的美就在于,通过使用很多简单的属性,你能创建出漂亮的消隐效果.其中代表性的一种就是CSS图片翻转效果,能让你看到一张卡片的正反两面上的内容.本文就是要用最简单的方法向大家 ...