本文整理汇总了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();
}
}
}
}
示例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();
}
}
}
}
示例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);
}
}
}
示例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());
}
示例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<>();
}
示例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();
}
}
}
}
示例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();
}
示例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();
}
};
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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();
}