Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
Copyright (C) GridGain Systems. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* _________ _____ __________________ _____
* __ ____/___________(_)______ /__ ____/______ ____(_)_______
* _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
* / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
* \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
*/
package org.gridgain.grid.thread;
import org.jetbrains.annotations.*;
import java.util.concurrent.*;
/**
* An {@link ExecutorService} that executes submitted tasks using pooled grid threads.
*/
public class GridThreadPoolExecutor extends ThreadPoolExecutor {
/** Default core pool size (value is {@code 100}). */
public static final int DFLT_CORE_POOL_SIZE = 100;
/**
* Creates a new service with default initial parameters.
* Default values are:
*
*
*
Name
*
Default Value
*
*
*
Core Pool Size
*
{@code 100} (see {@link #DFLT_CORE_POOL_SIZE}).
*
*
*
Maximum Pool Size
*
None, is it is not used for unbounded queues.
*
*
*
Keep alive time
*
No limit (see {@link Long#MAX_VALUE}).
*
*
*
Blocking Queue (see {@link BlockingQueue}).
*
Unbounded linked blocking queue (see {@link LinkedBlockingDeque}).
*
*
*/
public GridThreadPoolExecutor() {
this(
DFLT_CORE_POOL_SIZE,
DFLT_CORE_POOL_SIZE,
0,
new LinkedBlockingDeque(),
new GridThreadFactory(null),
null
);
}
/**
* Creates a new service with the given initial parameters.
*
* @param corePoolSize The number of threads to keep in the pool, even if they are idle.
* @param maxPoolSize 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 workQueue The queue to use for holding tasks before they are executed. This queue will hold only
* runnable tasks submitted by the {@link #execute(Runnable)} method.
*/
public GridThreadPoolExecutor(
int corePoolSize,
int maxPoolSize,
long keepAliveTime,
BlockingQueue workQueue) {
this(
corePoolSize,
maxPoolSize,
keepAliveTime,
workQueue,
new GridThreadFactory(null),
null
);
}
/**
* Creates a new service with the given initial parameters.
*
* @param corePoolSize The number of threads to keep in the pool, even if they are idle.
* @param maxPoolSize 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 workQ The queue to use for holding tasks before they are executed. This queue will hold only the
* runnable tasks submitted by the {@link #execute(Runnable)} method.
* @param hnd Optional handler to use when execution is blocked because the thread bounds and queue
* capacities are reached. If {@code null} then {@code AbortPolicy}
* handler is used by default.
*/
public GridThreadPoolExecutor(
int corePoolSize,
int maxPoolSize,
long keepAliveTime,
BlockingQueue workQ,
RejectedExecutionHandler hnd) {
this(
corePoolSize,
maxPoolSize,
keepAliveTime,
workQ,
new GridThreadFactory(null),
hnd
);
}
/**
* Creates a new service with default initial parameters.
* Default values are:
*
*
*
Name
*
Default Value
*
*
*
Core Pool Size
*
{@code 100} (see {@link #DFLT_CORE_POOL_SIZE}).
*
*
*
Maximum Pool Size
*
None, is it is not used for unbounded queues.
*
*
*
Keep alive time
*
No limit (see {@link Long#MAX_VALUE}).
*
*
*
Blocking Queue (see {@link BlockingQueue}).
*
Unbounded linked blocking queue (see {@link LinkedBlockingDeque}).
*
*
*
* @param gridName Name of the grid.
*/
public GridThreadPoolExecutor(String gridName) {
this(
DFLT_CORE_POOL_SIZE,
DFLT_CORE_POOL_SIZE,
0,
new LinkedBlockingDeque(),
new GridThreadFactory(gridName),
null
);
}
/**
* Creates a new service with the given initial parameters.
*
* @param gridName Name of the grid
* @param corePoolSize The number of threads to keep in the pool, even if they are idle.
* @param maxPoolSize 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 workQ The queue to use for holding tasks before they are executed. This queue will hold only
* runnable tasks submitted by the {@link #execute(Runnable)} method.
*/
public GridThreadPoolExecutor(
String gridName,
int corePoolSize,
int maxPoolSize,
long keepAliveTime,
BlockingQueue workQ) {
super(
corePoolSize,
maxPoolSize,
keepAliveTime,
TimeUnit.MILLISECONDS,
workQ,
new GridThreadFactory(gridName)
);
}
/**
* Creates a new service with the given initial parameters.
*
* @param gridName Name of the grid.
* @param corePoolSize The number of threads to keep in the pool, even if they are idle.
* @param maxPoolSize 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 workQ The queue to use for holding tasks before they are executed. This queue will hold only the
* runnable tasks submitted by the {@link #execute(Runnable)} method.
* @param hnd Optional handler to use when execution is blocked because the thread bounds and queue
* capacities are reached. If {@code null} then {@code AbortPolicy}
* handler is used by default.
*/
public GridThreadPoolExecutor(
String gridName,
int corePoolSize,
int maxPoolSize,
long keepAliveTime,
BlockingQueue workQ,
RejectedExecutionHandler hnd) {
this(
corePoolSize,
maxPoolSize,
keepAliveTime,
workQ,
new GridThreadFactory(gridName),
hnd
);
}
/**
* Creates a new service with the given initial parameters.
*
* @param corePoolSize The number of threads to keep in the pool, even if they are idle.
* @param maxPoolSize 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 workQ The queue to use for holding tasks before they are executed. This queue will hold only the
* runnable tasks submitted by the {@link #execute(Runnable)} method.
* @param threadFactory Thread factory.
* @param hnd Optional handler to use when execution is blocked because the thread bounds and queue
* capacities are reached. If {@code null} then {@code AbortPolicy}
* handler is used by default.
*/
public GridThreadPoolExecutor(
int corePoolSize,
int maxPoolSize,
long keepAliveTime,
BlockingQueue workQ,
ThreadFactory threadFactory,
@Nullable RejectedExecutionHandler hnd) {
super(
corePoolSize,
maxPoolSize,
keepAliveTime,
TimeUnit.MILLISECONDS,
workQ,
threadFactory,
hnd == null ? new AbortPolicy() : hnd
);
}
}