我想问下大家Executor框架中,如何判断线程池的目前的任务量,
for (int i=0;i<=500000;i++)
{
Task SendTask =new Task();//实现了Callable接口.
Future<Integer> future=exec.submit(SendTask);//如果目前任务已经饱和,我这里添加会阻塞吗?
}
for (int i=0;i<=500000;i++)
{
Task SendTask =new Task();//实现了Callable接口.
Future<Integer> future=exec.submit(SendTask);//如果目前任务已经饱和,我这里添加会阻塞吗?
}
解决方案 »
- 如何设置JFrame在桌面上的初始显示位置
- this在这个程序中的作用 在线等
- 再求String字符串与double的二维数组的互换
- 高分求救!关于xml
- 在JList中嵌入JCheckBox中遇到的问题
- 提供现成的java日志类,100分。。。。。。。。。。。。。
- String变量记录参数,都是以byte写入的,1作为分隔符,byte写入,我如何在String得到我的氖参数
- 最新的使JBUIDER变漂亮的插件,需要的进来
- 关于JTable:选择表里的一行,要求新弹出的一窗口里面TextField显示这行各个字段的内容,JTable有这样的ActionListener吗?
- 哪里有电子商务高手?
- 请问大家如何用正则表达式来匹配我需要的字符集
- 问下tomcat项目的问题
我的2G WindowsXP系统可以创建4000到5000。
* Creates a new <tt>ThreadPoolExecutor</tt> with the given initial
* parameters.
*
* @param corePoolSize the number of threads to keep in the
* pool, even if they are idle.
* @param maximumPoolSize the maximum number of threads to allow in the
* pool.
* @param keepAliveTime when the number of threads is greater than
* the core, this is the maximum time that excess idle threads
* will wait for new tasks before terminating.
* @param unit the time unit for the keepAliveTime
* argument.
* @param workQueue the queue to use for holding tasks before they
* are executed. This queue will hold only the <tt>Runnable</tt>
* tasks submitted by the <tt>execute</tt> method.
* @param threadFactory the factory to use when the executor
* creates a new thread.
* @param handler the handler to use when execution is blocked
* because the thread bounds and queue capacities are reached.
* @throws IllegalArgumentException if corePoolSize, or
* keepAliveTime less than zero, or if maximumPoolSize less than or
* equal to zero, or if corePoolSize greater than maximumPoolSize.
* @throws NullPointerException if <tt>workQueue</tt>
* or <tt>threadFactory</tt> or <tt>handler</tt> are null.
*/
public ThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue,
ThreadFactory threadFactory,
RejectedExecutionHandler handler) {
if (corePoolSize < 0 ||
maximumPoolSize <= 0 ||
maximumPoolSize < corePoolSize ||
keepAliveTime < 0)
throw new IllegalArgumentException();
if (workQueue == null || threadFactory == null || handler == null)
throw new NullPointerException();
this.corePoolSize = corePoolSize;
this.maximumPoolSize = maximumPoolSize;
this.workQueue = workQueue;
this.keepAliveTime = unit.toNanos(keepAliveTime);
this.threadFactory = threadFactory;
this.handler = handler;
}BlockingQueue<Runnable> workQueue,使用ArrayBlockingQueue的时候构造的时候有个等待队列的大小, 如果任务多于这个大小,那么默认好像是会抛弃策略.
如果使用LinkedBlockQueue的时候应该就不用怕了, 设置一下RejectedExecutionHandler handler为CallerRunsPolicy,默认是AbortPolicy