zoukankan      html  css  js  c++  java
  • sparkschedule任务类

     1 import java.util.concurrent.BlockingQueue;
     2 import java.util.concurrent.LinkedBlockingQueue;
     3 import java.util.concurrent.ThreadPoolExecutor;
     4 import java.util.concurrent.TimeUnit;
     5 
     6 /**
     7  * <p>spark 异常处理</p>
     8  *
     9  * @author
    10  * @version V1.0
    11  * @modify by user: {修改人} 2015年11月2日
    12  * @modify by reason:{方法名}:{原因}
    13  */
    14 public class SparkThreadScheduler {
    15 
    16     private static SparkThreadScheduler instance;
    17 
    18     private static int taskTotalNum = 2;
    19 
    20     // 阻塞式任务队列,用于存放提交的任务
    21     private final BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(taskTotalNum);
    22 
    23     // 任务处理线程池
    24     private final ThreadPoolExecutor threadPool = new ThreadPoolExecutor(taskTotalNum, taskTotalNum, 1,
    25             TimeUnit.HOURS, queue, new ThreadPoolExecutor.CallerRunsPolicy());
    26 
    27     /**
    28      * 私有构造函数
    29      */
    30     private SparkThreadScheduler() {
    31 
    32     }
    33 
    34     /**
    35      * 获取单例
    36      *
    37      * @return
    38      * @author
    39      */
    40     public static synchronized SparkThreadScheduler getInstance() {
    41         if (null == instance) {
    42             instance = new SparkThreadScheduler();
    43         }
    44         return instance;
    45     }
    46 
    47     /**
    48      * 执行任务提交
    49      *
    50      * @param thread
    51      * @author
    52      */
    53     public synchronized void execute(Thread thread) {
    54         threadPool.submit(thread);
    55     }
    56 
    57 }
  • 相关阅读:
    ASP.NET Core学习——7
    ASP.NET Core学习——6
    ASP.NET Core学习——6
    ASP.NET Core学习——5
    ASP.NET Core学习——4
    平衡的括号(名字怪怪的~)
    找复合单词
    卡片游戏
    Ducci 序列
    卡片游戏O(∩_∩)O
  • 原文地址:https://www.cnblogs.com/jinniezheng/p/6397358.html
Copyright © 2011-2022 走看看