Reputation: 764
I'm using Fabric / Crashlytics to track my app crashes and I have this crash:
Fatal Exception: java.lang.OutOfMemoryError: thread creation failed at java.lang.VMThread.create(VMThread.java) at java.lang.Thread.start(Thread.java:1050) at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:913) at java.util.concurrent.ThreadPoolExecutor.processWorkerExit(ThreadPoolExecutor.java:962) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1098) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) at java.lang.Thread.run(Thread.java:856)
I see 1230 threads, of which 1170 are from cling UPnP library, like this:
cling-1761 at java.lang.Object.wait(Object.java) at java.lang.Object.wait(Object.java:364) at org.eclipse.jetty.client.HttpExchange.waitForDone(HttpExchange.java:170) at org.fourthline.cling.transport.impl.jetty.StreamClientImpl$2.call(StreamClientImpl.java:115) at org.fourthline.cling.transport.impl.jetty.StreamClientImpl$2.call(StreamClientImpl.java:108) at java.util.concurrent.FutureTask.run(FutureTask.java:234) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) at java.lang.Thread.run(Thread.java:856)
Any idea why this librery is using too many threads? I think that I fix this problem I have not more crashes related with thread creation.
Thanks
Upvotes: 1
Views: 339
Reputation: 2008
When you init an UpnpServiceImpl, you can create your configuration to set the thread pool size. The example code is:
protected UpnpServiceConfiguration createConfiguration() {
return new AndroidUpnpServiceConfiguration() {
protected ExecutorService createDefaultExecutorService() {
return new ThreadPoolExecutor(10,
60,
60L,
TimeUnit.SECONDS,
new SynchronousQueue<Runnable>(),
new ClingThreadFactory(),
new ThreadPoolExecutor.DiscardPolicy());
}
@Override
public int getRegistryMaintenanceIntervalMillis() {
return 5000;
}
};
}
Upvotes: 0