Non utilizzare ForkJoinPool in Java EE. Solo il server delle applicazioni deve fornire costrutti per il parallelismo (come lo ManagedExecutorService in Java EE 7), perché threads have to be managed by the container.
Stranamente, c'è un messaggio nella mailing list menzionata in this answer che afferma che un ForkJoinPool si degraderà con grazia a thread singolo in un contenitore EE. L'ho provato con glassfish 4.1 e sono stati creati i soliti thread. L'esecuzione di questo codice:
@Singleton
public class SomeSingleton {
public void fireStream() {
IntStream.range(0, 32)
.parallel()
.mapToObj(i -> String.format("Task %d on thread %s",
i, Thread.currentThread().getName()))
.forEach(System.out::println);
}
}
ottengo il seguente output:
Info: Task 20 on thread http-listener-1(4)
Info: Task 10 on thread ForkJoinPool.commonPool-worker-3
Info: Task 21 on thread http-listener-1(4)
Info: Task 11 on thread ForkJoinPool.commonPool-worker-3
Info: Task 22 on thread http-listener-1(4)
Info: Task 8 on thread ForkJoinPool.commonPool-worker-3
Info: Task 23 on thread http-listener-1(4)
Info: Task 9 on thread ForkJoinPool.commonPool-worker-3
Info: Task 18 on thread http-listener-1(4)
Info: Task 14 on thread ForkJoinPool.commonPool-worker-3
Info: Task 19 on thread http-listener-1(4)
Info: Task 15 on thread ForkJoinPool.commonPool-worker-3
Info: Task 16 on thread http-listener-1(4)
Info: Task 17 on thread http-listener-1(4)
Info: Task 4 on thread http-listener-1(4)
Info: Task 5 on thread http-listener-1(4)
Info: Task 6 on thread http-listener-1(4)
Info: Task 7 on thread http-listener-1(4)
Info: Task 2 on thread http-listener-1(4)
Info: Task 3 on thread http-listener-1(4)
Info: Task 0 on thread http-listener-1(4)
Info: Task 1 on thread http-listener-1(4)
Info: Task 26 on thread http-listener-1(4)
Info: Task 27 on thread http-listener-1(4)
Info: Task 24 on thread http-listener-1(4)
Info: Task 25 on thread http-listener-1(4)
Info: Task 12 on thread http-listener-1(4)
Info: Task 13 on thread http-listener-1(4)
Info: Task 30 on thread http-listener-1(4)
Info: Task 31 on thread http-listener-1(4)
Info: Task 28 on thread ForkJoinPool.commonPool-worker-0
Info: Task 29 on thread ForkJoinPool.commonPool-worker-0
Forse il degrado sarà disponibile su Java EE 8, quando la maggior parte le singole specifiche faranno leva SE 8 caratteristiche.
Modifica
Ho controllato GlassFish 4.1.1 del codice sorgente, e non c'è un singolo uso di ForkJoinPool
, ForkJoinWorkerThreadFactory
o ForkJoinWorkerThread
. Pertanto, le risorse di parallelismo gestite dal server delle app non sono basate su nessuno di questi costrutti. Sfortunatamente, non c'è davvero nessun meccanismo di degrado disponibile.
L'ultimo che ho sentito (ed è passato un po 'di tempo) è qui: http://coopsoft.com/ar/Calamity2Article.html#EE – edharned