From a0cf121d7aa7c40d56f922d1a23348cdb0474ab5 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 8 Feb 2015 13:37:29 +0100 Subject: [PATCH] Make cached executor service use linked blocking queue Since e6045c659370d473bc18868ba2a2cd74d7a3856a the cached executor services maximum pool size is limited to concurrencyLevel (was previously Integer.MAX_VALUE). In order to prevent RejectExecutionException we need to use an queue which max size is greater than 1 (i.e. nont an SynchronousQueue). Connection closed with error java.util.concurrent.RejectedExecutionException: Task org.jivesoftware.smack.tcp.XMPPTCPConnection$2@41dce200 rejected from java.util.concurrent.ThreadPoolExecutor@41d59150[Running, pool size = 3, active threads = 3, queued tasks = 0, completed tasks = 4] at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2011) at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:793) at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1339) at org.jivesoftware.smack.AbstractXMPPConnection.asyncGo(AbstractXMPPConnection.java:1583) at org.jivesoftware.smack.tcp.XMPPTCPConnection.processHandledCount(XMPPTCPConnection.java:1655) at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$2300(XMPPTCPConnection.java:137) at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1083) at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPConnection.java:896) at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:911) at java.lang.Thread.run(Thread.java:841) --- .../java/org/jivesoftware/smack/AbstractXMPPConnection.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index 26327efd6..ba5e278ca 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -32,9 +32,9 @@ import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -286,7 +286,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { concurrencyLevel, // maximumPoolSize THREAD_KEEP_ALIVE_SECONDS, // keepAliveTime TimeUnit.SECONDS, // keepAliveTime unit, note that MINUTES is Android API 9 - new SynchronousQueue(), // workQueue + new LinkedBlockingQueue(), // workQueue new SmackExecutorThreadFactory( // threadFactory connectionCounterValue, "Cached Executor"