本文整理了Java中java.util.concurrent.ThreadPoolExecutor.execute()
方法的一些代码示例,展示了ThreadPoolExecutor.execute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadPoolExecutor.execute()
方法的具体详情如下:
包路径:java.util.concurrent.ThreadPoolExecutor
类名称:ThreadPoolExecutor
方法名:execute
[英]Executes the given task sometime in the future. The task may execute in a new thread or in an existing pooled thread. If the task cannot be submitted for execution, either because this executor has been shutdown or because its capacity has been reached, the task is handled by the current RejectedExecutionHandler.
[中]在将来的某个时候执行给定的任务。任务可以在新线程或现有池线程中执行。如果由于此执行器已关闭或已达到其容量而无法提交任务执行,则该任务将由当前的RejectedExecutionHandler处理。
代码示例来源:origin: skylot/jadx
protected void addTask(Runnable runnable) {
executor.execute(runnable);
}
代码示例来源:origin: xuxueli/xxl-job
public void addTrigger(final int jobId, final TriggerTypeEnum triggerType, final int failRetryCount, final String executorShardingParam, final String executorParam) {
triggerPool.execute(new Runnable() {
@Override
public void run() {
XxlJobTrigger.trigger(jobId, triggerType, failRetryCount, executorShardingParam, executorParam);
}
});
}
代码示例来源:origin: android10/Android-CleanArchitecture
@Override public void execute(@NonNull Runnable runnable) {
this.threadPoolExecutor.execute(runnable);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void execute(Runnable command) {
Runnable decorated = taskDecorator.decorate(command);
if (decorated != command) {
decoratedTaskMap.put(decorated, command);
}
super.execute(decorated);
}
};
代码示例来源:origin: facebook/litho
@Override
public boolean post(Runnable runnable) {
try {
sLayoutThreadPoolExecutor.execute(runnable);
return true;
} catch (RejectedExecutionException e) {
throw new RuntimeException("Cannot execute layout calculation task; " + e);
}
}
代码示例来源:origin: apache/incubator-dubbo
private static void newThreadToCloseExecutor(final ExecutorService es) {
if (!isTerminated(es)) {
shutdownExecutor.execute(new Runnable() {
@Override
public void run() {
try {
for (int i = 0; i < 1000; i++) {
es.shutdownNow();
if (es.awaitTermination(10, TimeUnit.MILLISECONDS)) {
break;
}
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
} catch (Throwable e) {
logger.warn(e.getMessage(), e);
}
}
});
}
}
代码示例来源:origin: apache/incubator-dubbo
private static void newThreadToCloseExecutor(final ExecutorService es) {
if (!isTerminated(es)) {
shutdownExecutor.execute(new Runnable() {
@Override
public void run() {
try {
for (int i = 0; i < 1000; i++) {
es.shutdownNow();
if (es.awaitTermination(10, TimeUnit.MILLISECONDS)) {
break;
}
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
} catch (Throwable e) {
logger.warn(e.getMessage(), e);
}
}
});
}
}
代码示例来源:origin: org.springframework/spring-context
@Override
public void execute(Runnable command) {
Runnable decorated = taskDecorator.decorate(command);
if (decorated != command) {
decoratedTaskMap.put(decorated, command);
}
super.execute(decorated);
}
};
代码示例来源:origin: weibocom/motan
protected void initConnections(boolean async) {
if (async) {
executor.execute(new Runnable() {
@Override
public void run() {
createConnections();
}
});
} else {
createConnections();
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void execute(Runnable command) {
if (command == null) {
throw new NullPointerException();
}
// do not increment in method beforeExecute!
submittedTaskCount.incrementAndGet();
try {
super.execute(command);
} catch (RejectedExecutionException rx) {
// retry to offer the task into queue.
final TaskQueue queue = (TaskQueue) super.getQueue();
try {
if (!queue.retryOffer(command, 0, TimeUnit.MILLISECONDS)) {
submittedTaskCount.decrementAndGet();
throw new RejectedExecutionException("Queue capacity is full.", rx);
}
} catch (InterruptedException x) {
submittedTaskCount.decrementAndGet();
throw new RejectedExecutionException(x);
}
} catch (Throwable t) {
// decrease any way
submittedTaskCount.decrementAndGet();
throw t;
}
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void execute(Runnable command) {
if (command == null) {
throw new NullPointerException();
}
// do not increment in method beforeExecute!
submittedTaskCount.incrementAndGet();
try {
super.execute(command);
} catch (RejectedExecutionException rx) {
// retry to offer the task into queue.
final TaskQueue queue = (TaskQueue) super.getQueue();
try {
if (!queue.retryOffer(command, 0, TimeUnit.MILLISECONDS)) {
submittedTaskCount.decrementAndGet();
throw new RejectedExecutionException("Queue capacity is full.", rx);
}
} catch (InterruptedException x) {
submittedTaskCount.decrementAndGet();
throw new RejectedExecutionException(x);
}
} catch (Throwable t) {
// decrease any way
submittedTaskCount.decrementAndGet();
throw t;
}
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void disconnected(Channel channel) throws RemotingException {
try {
checkQueueLength();
connectionExecutor.execute(new ChannelEventRunnable(channel, handler, ChannelState.DISCONNECTED));
} catch (Throwable t) {
throw new ExecutionException("disconnected event", channel, getClass() + " error when process disconnected event .", t);
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void connected(Channel channel) throws RemotingException {
try {
checkQueueLength();
connectionExecutor.execute(new ChannelEventRunnable(channel, handler, ChannelState.CONNECTED));
} catch (Throwable t) {
throw new ExecutionException("connect event", channel, getClass() + " error when process connected event .", t);
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void disconnected(Channel channel) throws RemotingException {
try {
checkQueueLength();
connectionExecutor.execute(new ChannelEventRunnable(channel, handler, ChannelState.DISCONNECTED));
} catch (Throwable t) {
throw new ExecutionException("disconnected event", channel, getClass() + " error when process disconnected event .", t);
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void connected(Channel channel) throws RemotingException {
try {
checkQueueLength();
connectionExecutor.execute(new ChannelEventRunnable(channel, handler, ChannelState.CONNECTED));
} catch (Throwable t) {
throw new ExecutionException("connect event", channel, getClass() + " error when process connected event .", t);
}
}
代码示例来源:origin: apache/zookeeper
/**
* Server receives a connection request and handles it asynchronously via
* separate thread.
*/
public void receiveConnectionAsync(final Socket sock) {
try {
connectionExecutor.execute(
new QuorumConnectionReceiverThread(sock));
connectionThreadCnt.incrementAndGet();
} catch (Throwable e) {
LOG.error("Exception handling connection, addr: {}, closing server connection",
sock.getRemoteSocketAddress());
closeSocket(sock);
}
}
代码示例来源:origin: weibocom/motan
protected void processHeartbeat(boolean isPass) {
for (String serviceid : serviceIds) {
try {
jobExecutor.execute(new HeartbeatJob(serviceid, isPass));
} catch (RejectedExecutionException ree) {
LoggerUtil.error("execute heartbeat job fail! serviceid:"
+ serviceid + " is rejected");
}
}
}
代码示例来源:origin: google/guava
public void testGetExitingExecutorService_executorDelegatesToOriginal() {
TestApplication application = new TestApplication();
ThreadPoolExecutor executor = mock(ThreadPoolExecutor.class);
ThreadFactory threadFactory = mock(ThreadFactory.class);
when(executor.getThreadFactory()).thenReturn(threadFactory);
application.getExitingExecutorService(executor).execute(EMPTY_RUNNABLE);
verify(executor).execute(EMPTY_RUNNABLE);
}
代码示例来源:origin: lingochamp/FileDownloader
public void execute(DownloadLaunchRunnable launchRunnable) {
launchRunnable.pending();
synchronized (this) {
runnablePool.put(launchRunnable.getId(), launchRunnable);
}
mThreadPool.execute(launchRunnable);
final int checkThresholdValue = 600;
if (mIgnoreCheckTimes >= checkThresholdValue) {
filterOutNoExist();
mIgnoreCheckTimes = 0;
} else {
mIgnoreCheckTimes++;
}
}
代码示例来源:origin: jeasonlzy/okhttp-OkGo
public UploadTask<T> start() {
if (OkUpload.getInstance().getTask(progress.tag) == null || UploadManager.getInstance().get(progress.tag) == null) {
throw new IllegalStateException("you must call UploadTask#save() before UploadTask#start()!");
}
if (progress.status != Progress.WAITING && progress.status != Progress.LOADING) {
postOnStart(progress);
postWaiting(progress);
priorityRunnable = new PriorityRunnable(progress.priority, this);
executor.execute(priorityRunnable);
} else {
OkLogger.w("the task with tag " + progress.tag + " is already in the upload queue, current task status is " + progress.status);
}
return this;
}
内容来源于网络,如有侵权,请联系作者删除!