当前位置: 首页>>代码示例>>Java>>正文


Java ThreadPoolExecutor.getQueue方法代码示例

本文整理汇总了Java中java.util.concurrent.ThreadPoolExecutor.getQueue方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadPoolExecutor.getQueue方法的具体用法?Java ThreadPoolExecutor.getQueue怎么用?Java ThreadPoolExecutor.getQueue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.ThreadPoolExecutor的用法示例。


在下文中一共展示了ThreadPoolExecutor.getQueue方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("tccTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (runnable instanceof RejectedRunnable) {
        ((RejectedRunnable) runnable).rejected();
    } else {
        if (!executor.isShutdown()) {
            BlockingQueue<Runnable> queue = executor.getQueue();
            int discardSize = queue.size() >> 1;
            for (int i = 0; i < discardSize; i++) {
                queue.poll();
            }

            try {
                queue.put(runnable);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:yu199195,项目名称:happylifeplat-tcc,代码行数:25,代码来源:RejectedPolicy.java

示例2: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("txTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (runnable instanceof RejectedRunnable) {
        ((RejectedRunnable) runnable).rejected();
    } else {
        if (!executor.isShutdown()) {
            BlockingQueue<Runnable> queue = executor.getQueue();
            int discardSize = queue.size() >> 1;
            for (int i = 0; i < discardSize; i++) {
                queue.poll();
            }

            try {
                queue.put(runnable);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:25,代码来源:RejectedPolicy.java

示例3: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public void rejectedExecution(Runnable task, ThreadPoolExecutor executor)
{
    ((DebuggableThreadPoolExecutor) executor).onInitialRejection(task);
    BlockingQueue<Runnable> queue = executor.getQueue();
    while (true)
    {
        if (executor.isShutdown())
        {
            ((DebuggableThreadPoolExecutor) executor).onFinalRejection(task);
            throw new RejectedExecutionException("ThreadPoolExecutor has shut down");
        }
        try
        {
            if (queue.offer(task, 1000, TimeUnit.MILLISECONDS))
            {
                ((DebuggableThreadPoolExecutor) executor).onFinalAccept(task);
                break;
            }
        }
        catch (InterruptedException e)
        {
            throw new AssertionError(e);
        }
    }
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:26,代码来源:DebuggableThreadPoolExecutor.java

示例4: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
    if (r instanceof AbstractRunnable) {
        if (((AbstractRunnable) r).isForceExecution()) {
            BlockingQueue<Runnable> queue = executor.getQueue();
            if (!(queue instanceof SizeBlockingQueue)) {
                throw new IllegalStateException("forced execution, but expected a size queue");
            }
            try {
                ((SizeBlockingQueue) queue).forcePut(r);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw new IllegalStateException("forced execution, but got interrupted", e);
            }
            return;
        }
    }
    rejected.inc();
    throw new EsRejectedExecutionException("rejected execution of " + r + " on " + executor, executor.isShutdown());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:EsAbortPolicy.java

示例5: init

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public void init(Context context, int count, Retrofit retrofit) {
  mContext = context.getApplicationContext();
  mDao = new DownloadDao(context.getApplicationContext());
  mDao.pauseAll();
  mThreadCount = count;
  mExecutor = new ThreadPoolExecutor(mThreadCount, mThreadCount, 2000, TimeUnit.MILLISECONDS,
      new LinkedBlockingQueue<Runnable>());
  mThreadQueue = (LinkedBlockingQueue<Runnable>) mExecutor.getQueue();
  if (retrofit == null) {
    retrofit =
        new Retrofit.Builder().baseUrl("http://blog.csdn.net/zggzcgy/article/details/23987637/")
            .client(getOkHttpClient())
            .build();
  }
  mRetrofit = retrofit;
  //下载api
  mDownloadApi = mRetrofit.create(DownloadApi.class);
  mCurrentTaskList = new LinkedHashMap<>();
}
 
开发者ID:MaYunFei,项目名称:RxJavaDownLoadMultipleFile,代码行数:20,代码来源:DownloadManager.java

示例6: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("MythTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (runnable instanceof RejectedRunnable) {
        ((RejectedRunnable) runnable).rejected();
    } else {
        if (!executor.isShutdown()) {
            BlockingQueue<Runnable> queue = executor.getQueue();
            int discardSize = queue.size() >> 1;
            for (int i = 0; i < discardSize; i++) {
                queue.poll();
            }

            try {
                queue.put(runnable);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:yu199195,项目名称:myth,代码行数:25,代码来源:RejectedPolicy.java

示例7: init

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public void init(Context context, int threadCount, OkHttpClient client) {
	setupDatabase(context);
	recoveryTaskState();

	mClient = client;
	mThreadCount = threadCount < 1 ? 1 : threadCount <= EasyConstants.MAX_THREAD_COUNT ? threadCount : EasyConstants.MAX_THREAD_COUNT;
	mExecutor = new ThreadPoolExecutor(
			mThreadCount,
			mThreadCount,
			20,
			TimeUnit.MILLISECONDS,
			new LinkedBlockingQueue<Runnable>()
			);
	mCurrentTaskList = new HashMap<>();
	mQueue = (LinkedBlockingQueue<Runnable>) mExecutor.getQueue();
}
 
开发者ID:LaurenceYang,项目名称:EasyHttp,代码行数:17,代码来源:EasyDownloadManager.java

示例8: getDefaultAsyncTaskNamesOnRejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * 在AsyncTask发生RejectedExecution时获取AsyncTask中任务类的外部类名称(如:new AsyncTask()匿名内部类所在的外部类),
 * 便于检查哪些任务被拒绝、哪些任务在队列里、哪些任务存在死循环问题;
 *
 * @return
 */
public static GetAsyncTaskNamesProxyOnRejectedExecution getDefaultAsyncTaskNamesOnRejectedExecution() {
    return new GetAsyncTaskNamesProxyOnRejectedExecution() {
        @Override
        public String getAsyncTaskNames(Runnable r, ThreadPoolExecutor executor) {
            StringBuilder result = new StringBuilder();
            result.append("r.OuterClass = " + getOuterClass(r));
            result.append("\nqueue.runnable.OuterClasses = [");
            BlockingQueue<Runnable> queue = executor.getQueue();
            boolean isFirst = false;
            for (Runnable task : queue) {
                if (!isFirst) {
                    isFirst = true;
                } else {
                    result.append("\n");
                }
                Object outerClass = getOuterClass(task);
                result.append(outerClass);
            }
            result.append("]");
            return result.toString();
        }
    };
}
 
开发者ID:miLLlulei,项目名称:Accessibility,代码行数:30,代码来源:AndroidUtilsCompat.java

示例9: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("txTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (!executor.isShutdown()) {
        BlockingQueue<Runnable> queue = executor.getQueue();
        int discardSize = queue.size() >> 1;
        for (int i = 0; i < discardSize; i++) {
            queue.poll();
        }
        queue.offer(runnable);
    }
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:16,代码来源:DiscardedPolicy.java

示例10: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("tccTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }
    if (!executor.isShutdown()) {
        BlockingQueue<Runnable> queue = executor.getQueue();
        int discardSize = queue.size() >> 1;
        for (int i = 0; i < discardSize; i++) {
            queue.poll();
        }
        queue.offer(runnable);
    }
}
 
开发者ID:yu199195,项目名称:happylifeplat-tcc,代码行数:15,代码来源:DiscardedPolicy.java

示例11: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("MythTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }
    if (!executor.isShutdown()) {
        BlockingQueue<Runnable> queue = executor.getQueue();
        int discardSize = queue.size() >> 1;
        for (int i = 0; i < discardSize; i++) {
            queue.poll();
        }
        queue.offer(runnable);
    }
}
 
开发者ID:yu199195,项目名称:myth,代码行数:15,代码来源:DiscardedPolicy.java

示例12: init

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public void init(Context context, int threadCount, OkHttpClient client) {
    mClient = client;
    mThreadCount = threadCount < 1 ? 1 : threadCount <= EasyConstants.MAX_THREAD_COUNT ? threadCount : EasyConstants.MAX_THREAD_COUNT;
    mExecutor = new ThreadPoolExecutor(
            mThreadCount,
            mThreadCount,
            20,
            TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>()
    );
    mCurrentTaskList = new HashMap<>();
    mQueue = (LinkedBlockingQueue<Runnable>) mExecutor.getQueue();
}
 
开发者ID:LaurenceYang,项目名称:EasyHttp,代码行数:14,代码来源:EasySimpleDownloadManager.java

示例13: saturatedSize

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * Returns maximum number of tasks that can be submitted to given
 * pool (with bounded queue) before saturation (when submission
 * throws RejectedExecutionException).
 */
static final int saturatedSize(ThreadPoolExecutor pool) {
    BlockingQueue<Runnable> q = pool.getQueue();
    return pool.getMaximumPoolSize() + q.size() + q.remainingCapacity();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:JSR166TestCase.java


注:本文中的java.util.concurrent.ThreadPoolExecutor.getQueue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。