| | |
| | | private ThreadPoolExecutor fastTriggerPool = null; |
| | | private ThreadPoolExecutor slowTriggerPool = null; |
| | | |
| | | public void start(){ |
| | | public void start() { |
| | | fastTriggerPool = new ThreadPoolExecutor( |
| | | 10, |
| | | XxlJobAdminConfig.getAdminConfig().getTriggerPoolFastMax(), |
| | | 60L, |
| | | TimeUnit.SECONDS, |
| | | new LinkedBlockingQueue<Runnable>(1000), |
| | | new ThreadFactory() { |
| | | @Override |
| | | public Thread newThread(Runnable r) { |
| | | return new Thread(r, "xxl-job, admin JobTriggerPoolHelper-fastTriggerPool-" + r.hashCode()); |
| | | } |
| | | }); |
| | | 10, |
| | | XxlJobAdminConfig.getAdminConfig().getTriggerPoolFastMax(), |
| | | 60L, |
| | | TimeUnit.SECONDS, |
| | | new LinkedBlockingQueue<Runnable>(1000), |
| | | new ThreadFactory() { |
| | | @Override |
| | | public Thread newThread(Runnable r) { |
| | | return new Thread(r, "xxl-job, admin JobTriggerPoolHelper-fastTriggerPool-" + r.hashCode()); |
| | | } |
| | | }); |
| | | |
| | | slowTriggerPool = new ThreadPoolExecutor( |
| | | 10, |
| | | XxlJobAdminConfig.getAdminConfig().getTriggerPoolSlowMax(), |
| | | 60L, |
| | | TimeUnit.SECONDS, |
| | | new LinkedBlockingQueue<Runnable>(2000), |
| | | new ThreadFactory() { |
| | | @Override |
| | | public Thread newThread(Runnable r) { |
| | | return new Thread(r, "xxl-job, admin JobTriggerPoolHelper-slowTriggerPool-" + r.hashCode()); |
| | | } |
| | | }); |
| | | 10, |
| | | XxlJobAdminConfig.getAdminConfig().getTriggerPoolSlowMax(), |
| | | 60L, |
| | | TimeUnit.SECONDS, |
| | | new LinkedBlockingQueue<Runnable>(2000), |
| | | new ThreadFactory() { |
| | | @Override |
| | | public Thread newThread(Runnable r) { |
| | | return new Thread(r, "xxl-job, admin JobTriggerPoolHelper-slowTriggerPool-" + r.hashCode()); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | // job timeout count |
| | | private volatile long minTim = System.currentTimeMillis()/60000; // ms > min |
| | | private volatile long minTim = System.currentTimeMillis() / 60000; // ms > min |
| | | private volatile ConcurrentMap<Integer, AtomicInteger> jobTimeoutCountMap = new ConcurrentHashMap<>(); |
| | | |
| | | |
| | |
| | | // choose thread pool |
| | | ThreadPoolExecutor triggerPool_ = fastTriggerPool; |
| | | AtomicInteger jobTimeoutCount = jobTimeoutCountMap.get(jobId); |
| | | if (jobTimeoutCount!=null && jobTimeoutCount.get() > 10) { // job-timeout 10 times in 1 min |
| | | if (jobTimeoutCount != null && jobTimeoutCount.get() > 10) { // job-timeout 10 times in 1 min |
| | | triggerPool_ = slowTriggerPool; |
| | | } |
| | | |
| | |
| | | } finally { |
| | | |
| | | // check timeout-count-map |
| | | long minTim_now = System.currentTimeMillis()/60000; |
| | | long minTim_now = System.currentTimeMillis() / 60000; |
| | | if (minTim != minTim_now) { |
| | | minTim = minTim_now; |
| | | jobTimeoutCountMap.clear(); |
| | | } |
| | | |
| | | // incr timeout-count-map |
| | | long cost = System.currentTimeMillis()-start; |
| | | long cost = System.currentTimeMillis() - start; |
| | | if (cost > 500) { // ob-timeout threshold 500ms |
| | | AtomicInteger timeoutCount = jobTimeoutCountMap.putIfAbsent(jobId, new AtomicInteger(1)); |
| | | if (timeoutCount != null) { |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | // ---------------------- helper ---------------------- |
| | | |
| | | private static JobTriggerPoolHelper helper = new JobTriggerPoolHelper(); |
| | |
| | | public static void toStart() { |
| | | helper.start(); |
| | | } |
| | | |
| | | public static void toStop() { |
| | | helper.stop(); |
| | | } |
| | |
| | | /** |
| | | * @param jobId |
| | | * @param triggerType |
| | | * @param failRetryCount |
| | | * >=0: use this param |
| | | * <0: use param from job info config |
| | | * @param failRetryCount >=0: use this param |
| | | * <0: use param from job info config |
| | | * @param executorShardingParam |
| | | * @param executorParam |
| | | * null: use job param |
| | | * not null: cover job param |
| | | * @param executorParam null: use job param |
| | | * not null: cover job param |
| | | */ |
| | | public static void trigger(int jobId, TriggerTypeEnum triggerType, int failRetryCount, String executorShardingParam, String executorParam, String addressList) { |
| | | helper.addTrigger(jobId, triggerType, failRetryCount, executorShardingParam, executorParam, addressList); |