线程的定时任务类ScheduledExecutorService
前言
最近再看dubbo源码的时候(DubboRegistry),有这么一段
// 定时任务执行器
private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1, new NamedThreadFactory("DubboRegistryReconnectTimer", true));
// 重连定时器,定时检查连接是否可用,不可用时,无限次重连
private final ScheduledFuture<?> reconnectFuture;
/..../
public DubboRegistry(Invoker<RegistryService> registryInvoker, RegistryService registryService) {
super(registryInvoker.getUrl());
this.registryInvoker = registryInvoker;
this.registryService = registryService;
// 启动重连定时器
int reconnectPeriod = registryInvoker.getUrl().getParameter(Constants.REGISTRY_RECONNECT_PERIOD_KEY, RECONNECT_PERIOD_DEFAULT);
reconnectFuture = scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {
public v