Java中定时任务Timer工具类提供了计划任务的实现,但是Timer工具类是以队列的方式来管理线程的,并不是以线程池的方式,这样在高并发的情况下,运行效率会有点低. ScheduleExecutorService 主要作用是将定时任务与线程池结合使用. ScheduleExecutorService 的父接口是Executor,父类是ThreadPoolExecutor. 看个例子 final SimpleDateFormat sf = new SimpleDateFormat("yyyy-M…
1.前言 ReentrantLock可以有公平锁和非公平锁的不同实现,只要在构造它的时候传入不同的布尔值,继续跟进下源码我们就能发现,关键在于实例化内部变量sync的方式不同,如下所示: /** * Creates an instance of {@code ReentrantLock} with the * given fairness policy. * * @param fair {@code true} if this lock should use a fair ordering po…