com.github.ltsopensource.tasktracker.runner
Class RunnerPool

java.lang.Object
  extended by com.github.ltsopensource.tasktracker.runner.RunnerPool

public class RunnerPool
extends Object

Author:
Robert HG (254963746@qq.com) on 8/14/14. 线程池管理

Nested Class Summary
 class RunnerPool.RunningJobManager
          用来管理正在执行的任务
 
Constructor Summary
RunnerPool(TaskTrackerAppContext appContext)
           
 
Method Summary
 void execute(com.github.ltsopensource.core.domain.JobMeta jobMeta, RunnerCallback callback)
           
 int getAvailablePoolSize()
          得到当前可用的线程数
 RunnerFactory getRunnerFactory()
           
 RunnerPool.RunningJobManager getRunningJobManager()
           
 int getWorkThread()
          得到最大线程数
 void setWorkThread(int workThread)
           
 void shutDown()
           
 void stopWorking()
          执行该方法,线程池的状态立刻变成STOP状态,并试图停止所有正在执行的线程,不再处理还在池队列中等待的任务,当然,它会返回那些未执行的任务。 它试图终止线程的方法是通过调用Thread.interrupt()方法来实现的,但是大家知道,这种方法的作用有限, 如果线程中没有sleep 、wait、Condition、定时锁等应用, interrupt()方法是无法中断当前的线程的。 所以,ShutdownNow()并不代表线程池就一定立即就能退出,它可能必须要等待所有正在执行的任务都执行完成了才能退出。 特殊的时候可以通过使用InterruptibleJobRunner来解决
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RunnerPool

public RunnerPool(TaskTrackerAppContext appContext)
Method Detail

execute

public void execute(com.github.ltsopensource.core.domain.JobMeta jobMeta,
                    RunnerCallback callback)
             throws NoAvailableJobRunnerException
Throws:
NoAvailableJobRunnerException

getAvailablePoolSize

public int getAvailablePoolSize()
得到当前可用的线程数


setWorkThread

public void setWorkThread(int workThread)

getWorkThread

public int getWorkThread()
得到最大线程数


getRunnerFactory

public RunnerFactory getRunnerFactory()

stopWorking

public void stopWorking()
执行该方法,线程池的状态立刻变成STOP状态,并试图停止所有正在执行的线程,不再处理还在池队列中等待的任务,当然,它会返回那些未执行的任务。 它试图终止线程的方法是通过调用Thread.interrupt()方法来实现的,但是大家知道,这种方法的作用有限, 如果线程中没有sleep 、wait、Condition、定时锁等应用, interrupt()方法是无法中断当前的线程的。 所以,ShutdownNow()并不代表线程池就一定立即就能退出,它可能必须要等待所有正在执行的任务都执行完成了才能退出。 特殊的时候可以通过使用InterruptibleJobRunner来解决


shutDown

public void shutDown()

getRunningJobManager

public RunnerPool.RunningJobManager getRunningJobManager()


Copyright © 2017. All rights reserved.