A heads up, the graceful degradation to single thread is not available. I also thought it was because of Shorn's answer and that mailing list discussion, but I found out it wasn't while researching for this question. The mechanism is not in the Java EE 7 spec and it's not in glassfish 4.1. Even if another container does it, it won't be portable.
You can test this by calling the following method:
@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);
}
}
And you'll get something like:
Info: Task 20 on thread http-listener-1(4)
Info: Task 10 on thread ForkJoinPool.commonPool-worker-3
Info: Task 28 on thread ForkJoinPool.commonPool-worker-0
...
I've also checked glassfish 4.1.1 source code, and there isn't a single use of ForkJoinPool
, ForkJoinWorkerThreadFactory
or ForkJoinWorkerThread
.
The mechanism could be added to EE 8, since many frameworks will leverage jdk8 features, but I don't know if it's part of the spec.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…