Android之ThreadPoolExecutor


Public Constructors
ThreadPoolExecutor(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.                          

void allowCoreThreadTimeOut(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.
boolean allowsCoreThreadTimeOut()
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.
boolean awaitTermination(long timeout, TimeUnit unit)
void execute( Runnable command)
Executes the given task sometime in the future.
int getActiveCount()
Returns the approximate number of threads that are actively executing tasks.
long getCompletedTaskCount()
Returns the approximate total number of tasks that have completed execution.
int getCorePoolSize()
Returns the core number of threads.
long getKeepAliveTime( 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.
int getLargestPoolSize()
Returns the largest number of threads that have ever simultaneously been in the pool.
int getMaximumPoolSize()
Returns the maximum allowed number of threads.
int getPoolSize()
Returns the current number of threads in the pool.
BlockingQueue< Runnable> getQueue()
Returns the task queue used by this executor.
RejectedExecutionHandler getRejectedExecutionHandler()
Returns the current handler for unexecutable tasks.
long getTaskCount()
Returns the approximate total number of tasks that have ever been scheduled for execution.
ThreadFactory getThreadFactory()
Returns the thread factory used to create new threads.
boolean isShutdown()
boolean isTerminated()是否终止
boolean isTerminating()
Returns true if this executor is in the process of terminating after shutdown() or shutdownNow() but has not completely terminated.
int prestartAllCoreThreads()
Starts all core threads, causing them to idly wait for work.启动所有的内核线程,使他们为工作干等着。
boolean prestartCoreThread()
Starts a core thread, causing it to idly wait for work.启动一个内核线程,使他们
void purge()
Tries to remove from the work queue all Future tasks that have been cancelled.试图从工作队列中删除已被取消的所有未来任务。
boolean remove( 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.
void setCorePoolSize(int corePoolSize)
Sets the core number of threads.
void setKeepAliveTime(long time, TimeUnit unit)
Sets the time limit for which threads may remain idle before being terminated.
void setMaximumPoolSize(int maximumPoolSize)
Sets the maximum allowed number of threads.
void setRejectedExecutionHandler( RejectedExecutionHandler handler)
Sets a new handler for unexecutable tasks.
void setThreadFactory( ThreadFactory threadFactory)
Sets the thread factory used to create new threads.
void shutdown()
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.
String toString()
Returns a string identifying this pool, as well as its state, including indications of run state and estimated worker and task counts.                          

Protected Methods:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值