Android之ThreadPoolExecutor

来源:互联网 发布:dm500账号上传软件 编辑:程序博客网 时间:2024/05/19 16:48


Public ConstructorsThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue)

Creates a new ThreadPoolExecutor with the given initial parameters and default thread factory and rejected execution handler.
ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue,ThreadFactory threadFactory)
Creates a new ThreadPoolExecutor with the given initial parameters and default rejected execution handler.
ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue,RejectedExecutionHandler handler)
Creates a new ThreadPoolExecutor with the given initial parameters and default thread factory.
ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue,ThreadFactory threadFactory, RejectedExecutionHandler handler)
Creates a new ThreadPoolExecutor with the given initial parameters.                          

voidallowCoreThreadTimeOut(boolean value)

Sets the policy governing whether core threads may time out and terminate if no tasks arrive within the keep-alive time, being replaced if needed when new tasks arrive.
booleanallowsCoreThreadTimeOut()
Returns true if this pool allows core threads to time out and terminate if no tasks arrive within the keepAlive time, being replaced if needed when new tasks arrive.
booleanawaitTermination(long timeout, TimeUnit unit)voidexecute(Runnable command)
Executes the given task sometime in the future.
intgetActiveCount()
Returns the approximate number of threads that are actively executing tasks.
longgetCompletedTaskCount()
Returns the approximate total number of tasks that have completed execution.
intgetCorePoolSize()
Returns the core number of threads.
longgetKeepAliveTime(TimeUnit unit)
Returns the thread keep-alive time, which is the amount of time that threads in excess of the core pool size may remain idle before being terminated.
intgetLargestPoolSize()
Returns the largest number of threads that have ever simultaneously been in the pool.
intgetMaximumPoolSize()
Returns the maximum allowed number of threads.
intgetPoolSize()
Returns the current number of threads in the pool.
BlockingQueue<Runnable>getQueue()
Returns the task queue used by this executor.
RejectedExecutionHandlergetRejectedExecutionHandler()
Returns the current handler for unexecutable tasks.
longgetTaskCount()
Returns the approximate total number of tasks that have ever been scheduled for execution.
ThreadFactorygetThreadFactory()
Returns the thread factory used to create new threads.
booleanisShutdown()booleanisTerminated()是否终止booleanisTerminating()
Returns true if this executor is in the process of terminating aftershutdown() orshutdownNow() but has not completely terminated.
intprestartAllCoreThreads()
Starts all core threads, causing them to idly wait for work.启动所有的内核线程,使他们为工作干等着。
booleanprestartCoreThread()
Starts a core thread, causing it to idly wait for work.启动一个内核线程,使他们
voidpurge()
Tries to remove from the work queue all Future tasks that have been cancelled.试图从工作队列中删除已被取消的所有未来任务。
booleanremove(Runnable task)
Removes this task from the executor's internal queue if it is present, thus causing it not to be run if it has not already started.
voidsetCorePoolSize(int corePoolSize)
Sets the core number of threads.
voidsetKeepAliveTime(long time, TimeUnit unit)
Sets the time limit for which threads may remain idle before being terminated.
voidsetMaximumPoolSize(int maximumPoolSize)
Sets the maximum allowed number of threads.
voidsetRejectedExecutionHandler(RejectedExecutionHandler handler)
Sets a new handler for unexecutable tasks.
voidsetThreadFactory(ThreadFactory threadFactory)
Sets the thread factory used to create new threads.
voidshutdown()
Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
List<Runnable>shutdownNow()
Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.
StringtoString()
Returns a string identifying this pool, as well as its state, including indications of run state and estimated worker and task counts.                          

Protected Methods:

voidafterExecute(Runnable r, Throwable t)

Method invoked upon completion of execution of the given Runnable.在给定运行调用执行完成的方法。
voidbeforeExecute(Thread t, Runnable r)
Method invoked prior to executing the given Runnable in the given thread.
voidfinalize()
Invokes shutdown when this executor is no longer referenced and it has no threads.当这个执行程序不再被引用时,它会调用它,它没有线程。
voidterminated()
Method invoked when the Executor has terminated.                          
用法:http://blog.sina.com.cn/s/blog_80723de801011xct.html

0 0
原创粉丝点击