Anyone else out there having a resource issue with threads when Atmosphere is used to push to UI threads?
I’ve noticed that one of the two code blocks is always called from when a background thread accesses UI threads:
From org.atmosphere.util.ExecutorsFactory
public final static class AtmosphereThreadFactory implements ThreadFactory {
private final AtomicInteger count = new AtomicInteger();
private final boolean shared;
private final String name;
public AtmosphereThreadFactory(boolean shared, String name) {
this.shared = shared;
this.name = name;
}
@Override
public Thread newThread(final Runnable runnable) {
Thread t = new Thread(runnable, (shared ? "Atmosphere-Shared-" : name) + count.getAndIncrement());
t.setDaemon(true);
return t;
}
}
or
From org.atmosphere.util.ForkJoinPool
public ForkJoinPool(boolean shared, final String threadName) {
this.shared = shared;
forkJoinPool = new java.util.concurrent.ForkJoinPool(Runtime.getRuntime().availableProcessors(), new java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory() {
@Override
public java.util.concurrent.ForkJoinWorkerThread newThread(java.util.concurrent.ForkJoinPool pool) {
return new JDK7ForkJoinWorkerThread(pool, ForkJoinPool.this.shared, threadName);
}
}, null, false);
logger.info("Using ForkJoinPool {}. Set the {} to -1 to fully use its power.", forkJoinPool.getClass().getName(), ApplicationConfig.BROADCASTER_ASYNC_WRITE_THREADPOOL_MAXSIZE);
}
In each instance a new Atmosphere-Shared-xxx
thread is spawned instead of being executed in a shared thread pool. So, in my case, if I have a few UI’s open and a lot of data is being pushed them them, then I very quickly run out of resources and the UI’s all hang until the number of threads recovers enough to serve the new requests.
Is there a way to use a different implementation of org.atmosphere.util.ExecutorsFactory
so that instead of Thread t = new Thread(runnable, (shared ? "Atmosphere-Shared-" : name) + count.getAndIncrement());
, I could instead just execute the runnable in a pre-existing fixed thread pool?
Atmosphere Framework 2.4.30.vaadin1
Vaadin 8.5.2
Tomcat 8.5.34
Spring 5.1.3.RELEASE
vaadin-spring-boot-starter 3.1.1