package com.da.tool.guava;

import com.google.common.util.concurrent.AbstractScheduledService;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit; /**
*/
public class SchedulerJob extends AbstractScheduledService { private List<String> list; private static Boolean isEnd = false; @Override
protected void runOneIteration() throws Exception {
System.out.println("Add element to list ..........");
list.add("test");
if(list.size()>){
System.out.println("ShutDown job ..........");
isEnd = true;
this.stopAndWait();
}
} @Override
protected void startUp() throws Exception {
System.out.println("Job start ..........");
list = new ArrayList<>();
} @Override
protected void shutDown() throws Exception {
System.out.println("Job end ..........");
} @Override
protected Scheduler scheduler() {
return Scheduler.newFixedRateSchedule(,, TimeUnit.SECONDS);
} public static void main(String[] args) {
SchedulerJob schedulerJob =new SchedulerJob();
try {
schedulerJob.startAndWait();
} catch (Exception e) {
e.printStackTrace();
}
while(!isEnd){
try {
Thread.sleep();
} catch (InterruptedException e) {
e.getStackTrace();
}
}
System.exit();
}
}

39 (guava包)AbstractScheduledService的使用的更多相关文章

  1. Guava包学习---Lists

    Guava包是我最近项目中同事推荐使用的,是google推出的库.里面的功能非常多,包括了集合.缓存.原生类型支持.并发库.通用注解.字符串处理.IO等.我们项目中使用到了guava依赖,但是实际上只 ...

  2. google Guava包的reflection(反射)解析

    译者:万天慧(武祖) 由于类型擦除,你不能够在运行时传递泛型类对象——你可能想强制转换它们,并假装这些对象是有泛型的,但实际上它们没有. 举个例子: ArrayList<String> s ...

  3. Guava包学习---Maps

    Maps包方法列表: 还是泛型创建Map: public static <K, V> HashMap<K, V> newHashMap() { return new HashM ...

  4. com.google.guava 包解析 ——Google Guava官方教程(中文版)

    全网址           http://ifeve.com/google-guava/ 竹子博客:  http://www.cnblogs.com/peida/archive/2013/06/08/ ...

  5. google Guava包的ListenableFuture解析

     一. ListenableFuture是用来增强Future的功能的. 我们知道Future表示一个异步计算任务,当任务完成时可以得到计算结果.如果我们希望一旦计算完成就拿到结果展示给用户或者做另外 ...

  6. Guava包学习--Hash

    我们HashMap会有一个rehash的过程,为什么呢?因为java内建的散列码被限制为32位,而且没有分离散列算法和所作用的数据,所以替代算法比较难做.我们使用HashMap的时候它自身有一个reh ...

  7. Guava包学习--EventBus

    之前没用过这个EventBus,然后看了一下EventBus的源码也没看明白,(-__-)b.反正大概就是弄一个优雅的方式实现了观察者模式吧.慢慢深入学习一下. 观察者模式其实就是生产者消费者的一个变 ...

  8. Guava包学习---I/O

    Guava的I/O平时使用不太多,目前项目原因导致基本上只有在自己写一些文本处理小工具才用得到.但是I/O始终是程序猿最常遇到的需求和面试必问的知识点之一.同时Guava的I/O主要面向是时JDK5和 ...

  9. Guava包学习-Cache

    这段时间用到了ehcache和memcache,memcache只用来配置在tomcat中做负载均衡过程中的session共享,然后ehcache用来存放需要的程序中缓存. Guava中的Cache和 ...

随机推荐

  1. 解决新版Pycharm中Matplotlib图像不在弹出独立的显示窗口问题

    官方说明链接: https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000736584-SciView-in-PyCh ...

  2. JAVA(4)之关于项目部署在tomcat

    关于项目部署的报错问题一直是找不到项目 在重装几次tomcat9和tomcat7后找到了原因,关键原因是访问路径不正确,项目名拼写错误. 排除问题的思路如下(控制变量法) 工作方法和思路 列出步骤,从 ...

  3. [蓝桥杯][基础训练]2n皇后问题

    Description 给定一个n*n的棋盘,棋盘中有一些位置不能放皇后.现在要向棋盘中放入n个黑皇后和n个白皇后,使任意的两个黑皇后都不在同一行.同一列或同一条对角线上,任意的两个白皇后都不在同一行 ...

  4. ListView 基础列表组件、水平 列表组件、图标组件

    一.Flutter 列表组件概述 列表布局是我们项目开发中最常用的一种布局方式.Flutter 中我们可以通过 ListView 来定义 列表项,支持垂直和水平方向展示.通过一个属性就可以控制列表的显 ...

  5. 学习笔记(24)- plato-训练中文模型

    先处理中文语料.参考上篇笔记 1. 准备model_definition_file文件 官方文档给了例子, plato/example/config/ludwig/metalWOZ_seq2seq_l ...

  6. 【JavaWeb】Spring入门——HelloWorld

    0.为什么要使用Spring https://www.cnblogs.com/zmmi/p/7922186.html 1. 下载jar包 https://blog.csdn.net/qq_435401 ...

  7. 记C++中发现的隐式转换问题

    #include <iostream> #include <string> using std::cin; using std::cout; using std::endl; ...

  8. 模仿.NET框架ArrayList写一个自己的动态数组类MyArrayList,揭示foreach实现原理

    通过.NET反编译工具可以查看到ArrayList内部的代码,发现ArrayList并非由链表实现,而是由一个不断扩容的数组对象组成. 下面模仿ArrayList写一个自己的MyArrayList. ...

  9. Plastic Bottle Manufacturer Tips - Attention To Plastic Bottle Processing Technology

    In fact, the processing technology of plastic bottles is actually quite strict. In fact, regular man ...

  10. 数据表损坏:Incorrect key file for table

    最近做项目过程中,调用数据库内容,老是出现一些类似于数据表损坏的提示信息(Incorrect key file for table edison_category),查询不到数据,很是恼火,后来冷静下 ...