AnsweredAssumed Answered

Smack create too much threads with newCachedThreadPool

Question asked by sigmon on Jul 27, 2017
Latest reply on Jul 28, 2017 by Flow

when I need to send a large number of IQ in short time, smack will create large number of thread with CachedThreadPool. And this cause crashes on Huawei phones with Android 7.0 or higher.

I got

"java.lang.OutOfMemoryError

pthread_create (1040KB stack) failed: Out of memory

 

1 java.lang.Thread.nativeCreate(Native Method)

2 java.lang.Thread.start(Thread.java:745)

3 java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:941)

4 java.util.concurrent.ThreadPoolExecutor.processWorkerExit(ThreadPoolExecutor.jav a:1009)

5 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1151)

6 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)

7 java.lang.Thread.run(Thread.java:776)

". When I reappear the crash, I found more then 120 thread create by "Smack-Cached Executor", and I modify the cachedExecutorService as newFixedThreadPool (in smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java), the APP works well.

 

I hope this will help.

Outcomes