ScheduledExecutorService中scheduleAtFixedRate方法与scheduleWithFixedDelay方法的区别 ScheduledThreadPoolExecutor继承自ThreadPoolExecutor,可以作为线程池来使用,同时实现了ScheduledExecutorService接口,来执行一些周期性的任务.ScheduledExecutorService一般常用的方法主要就4个 public ScheduledFuture<?> schedul…
本文记录: 1,使用ScheduledExecutorService的 scheduleAtFixedRate 方法执行周期性任务的过程,讨论了在任务周期执行过程中出现了异常,会导致周期任务失败. 2,使用普通的Thread类来执行任务,在main线程中周期性创建线程,提交任务.然后,使用UncaughtExceptionHandler来处理异常. 一,正常任务执行 负责执行任务的线程类如下:(一个计算阶乘的任务,计算5以上的阶乘,就会抛出异常) public class FactorialCa…
java并发之固定对象与实例 Immutable Objects An object is considered immutable if its state cannot change after it is constructed. Maximum reliance on immutable objects is widely accepted as a sound strategy for creating simple, reliable code. Immutable objects…
在上篇博客中分析了hashmap的用法,详情查看java并发之hashmap 本篇博客重点分析下hashmap的源码(基于JDK1.8) 一.成员变量 HashMap有以下主要的成员变量 /** * The default initial capacity - MUST be a power of two. 默认初始容量 */ static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16 /** * The maximum capa…