本文整理了Java中java.util.concurrent.ThreadPoolExecutor.remove()
方法的一些代码示例,展示了ThreadPoolExecutor.remove()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadPoolExecutor.remove()
方法的具体详情如下:
包路径:java.util.concurrent.ThreadPoolExecutor
类名称:ThreadPoolExecutor
方法名:remove
[英]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.
This method may be useful as one part of a cancellation scheme. It may fail to remove tasks that have been converted into other forms before being placed on the internal queue. For example, a task entered using submit might be converted into a form that maintains Future status. However, in such cases, method #purge may be used to remove those Futures that have been cancelled.
[中]如果存在此任务,则将其从执行器的内部队列中移除,从而导致尚未启动的任务无法运行。
作为取消方案的一部分,这种方法可能很有用。它可能无法删除在放入内部队列之前已转换为其他形式的任务。例如,使用submit输入的任务可能会转换为一个表单,以维护未来的状态。然而,在这种情况下,可以使用#清除方法来清除已取消的期货。
代码示例来源:origin: facebook/litho
@Override
public void removeCallbacks(Runnable runnable) {
sLayoutThreadPoolExecutor.remove(runnable);
}
代码示例来源:origin: PipelineAI/pipeline
@Override
public void unsubscribe() {
executor.remove(f);
if (shouldInterruptThread.call()) {
f.cancel(true);
} else {
f.cancel(false);
}
}
代码示例来源:origin: GitLqr/LQRWeChat
/**
* 移除任务
*
* @param task
*/
public void removeTask(Runnable task) {
initThreadPoolExecutor();
mExecutor.remove(task);
}
}
代码示例来源:origin: io.netty/netty
@Override
public boolean remove(Runnable task) {
boolean removed = super.remove(task);
if (removed) {
decreaseCounter(task);
}
return removed;
}
代码示例来源:origin: Rukey7/MvpApp
/**
* 取消所有线程
*/
public void cancelAll() {
synchronized (this) {
for (DownloadTask task : mRunnableHolder.values()) {
mRunnablePool.remove(task);
if (task != null) {
task.cancel();
}
}
mRunnableHolder.clear();
}
}
代码示例来源:origin: jeasonlzy/okhttp-OkGo
/** 暂停的方法 */
public void pause() {
executor.remove(priorityRunnable);
if (progress.status == Progress.WAITING) {
postPause(progress);
} else if (progress.status == Progress.LOADING) {
progress.speed = 0;
progress.status = Progress.PAUSE;
} else {
OkLogger.w("only the task with status WAITING(1) or LOADING(2) can pause, current status is " + progress.status);
}
}
代码示例来源:origin: jeasonlzy/okhttp-OkGo
/** 暂停的方法 */
public void pause() {
executor.remove(priorityRunnable);
if (progress.status == Progress.WAITING) {
postPause(progress);
} else if (progress.status == Progress.LOADING) {
progress.speed = 0;
progress.status = Progress.PAUSE;
} else {
OkLogger.w("only the task with status WAITING(1) or LOADING(2) can pause, current status is " + progress.status);
}
}
代码示例来源:origin: lingochamp/FileDownloader
public void cancel(final int id) {
filterOutNoExist();
synchronized (this) {
DownloadLaunchRunnable r = runnablePool.get(id);
if (r != null) {
r.pause();
boolean result = mThreadPool.remove(r);
if (FileDownloadLog.NEED_LOG) {
// If {@code result} is false, must be: the Runnable has been running before
// invoke this method.
FileDownloadLog.d(this, "successful cancel %d %B", id, result);
}
}
runnablePool.remove(id);
}
}
代码示例来源:origin: Rukey7/MvpApp
/**
* 取消线程
* @param url 线程url
* @param isDel 是否删除任务
*/
public void cancel(String url, boolean isDel) {
synchronized (this) {
if (mRunnableHolder.containsKey(url)) {
DownloadTask runnable = mRunnableHolder.get(url);
mRunnablePool.remove(runnable);
if (runnable != null) {
if (isDel) {
runnable.cancel();
} else {
runnable.stop();
}
}
mRunnableHolder.remove(url);
}
}
}
代码示例来源:origin: lingochamp/FileDownloader
public void expire(final FileDownloadListener listener) {
if (listener == null) {
FileDownloadLog.w(this, "want to expire by listener, but the listener provided is"
+ " null");
return;
}
List<Runnable> needPauseList = new ArrayList<>();
for (Runnable runnable : mWorkQueue) {
final LaunchTaskRunnable launchTaskRunnable = (LaunchTaskRunnable) runnable;
if (launchTaskRunnable.isSameListener(listener)) {
launchTaskRunnable.expire();
needPauseList.add(runnable);
}
}
if (needPauseList.isEmpty()) {
return;
}
if (FileDownloadLog.NEED_LOG) {
FileDownloadLog.d(this, "expire %d tasks with listener[%s]", needPauseList.size(),
listener);
}
for (Runnable runnable : needPauseList) {
mPool.remove(runnable);
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
/**
* Drains the Queue for the provided key.
*
* @param keyName the key to drain the Queue for
*/
public void drain(String keyName) {
try {
Runnable e;
while ((e = queue.deleteByName(keyName)) != null) {
executor.remove(e);
}
writeLock(keyName);
try {
keyQueues.get(keyName).clear();
} finally {
writeUnlock(keyName);
}
} catch (ExecutionException ex) {
//NOP
}
}
代码示例来源:origin: robovm/robovm
if (! isRunning(recheck) && remove(command))
reject(command);
else if (workerCountOf(recheck) == 0)
代码示例来源:origin: didi/DoraemonKit
/**
* 移除任务
*/
public void remove(Runnable task) {
initThreadPoolExecutor();
mExecutor.remove(task);
}
}
代码示例来源:origin: moagrius/TileView
public void destroy(boolean removeFromQueue) {
if (mState == State.IDLE) {
return;
}
if (removeFromQueue) {
mThreadPoolExecutor.remove(this);
}
if (mState == State.DECODED) {
mMemoryCache.put(getCacheKey(), mBitmap);
}
mBitmap = null;
mDrawingOptions.inBitmap = null;
// since tiles are pooled and reused, make sure to reset the cache key or you'll render the wrong tile from cache
mCacheKey = null;
mState = State.IDLE;
mListener.onTileDestroyed(this);
}
代码示例来源:origin: tomahawk-player/tomahawk-android
public boolean stop(Query query) {
boolean success = false;
Collection<TomahawkRunnable> runnables = mQueryRunnableMap.remove(query);
if (runnables != null) {
for (TomahawkRunnable r : runnables) {
mThreadPool.remove(r);
success = true;
}
}
return success;
}
代码示例来源:origin: com.bugvm/bugvm-rt
public synchronized void cancel(Object tag) {
List<Job> jobs = enqueuedJobs.remove(tag);
if (jobs == null) return;
for (Job job : jobs) {
executorService.remove(job);
}
}
代码示例来源:origin: com.netflix.hystrix/hystrix-core
@Override
public void unsubscribe() {
executor.remove(f);
if (shouldInterruptThread.call()) {
f.cancel(true);
} else {
f.cancel(false);
}
}
代码示例来源:origin: de.dentrassi.eclipse.neoscada.utils/org.eclipse.scada.utils
@Override
public boolean remove ( final Runnable task )
{
final boolean result = super.remove ( task );
updateCount ();
return result;
}
代码示例来源:origin: org.apache.mina/mina-core
@Override
public boolean remove(Runnable task) {
boolean removed = super.remove(task);
if (removed) {
getQueueHandler().polled(this, (IoEvent) task);
}
return removed;
}
代码示例来源:origin: org.apache.directory.api/api-ldap-client-all
@Override
public boolean remove(Runnable task) {
boolean removed = super.remove(task);
if (removed) {
getQueueHandler().polled(this, (IoEvent) task);
}
return removed;
}
内容来源于网络,如有侵权,请联系作者删除!