Injectable, Configurable, Resilient and Monitorable ThreadPools in Java EE 7 -- Porcupine Is Available
The Apache 2.0 licensed Project Porcupine is based on JSR 236: Concurrency Utilities for Java EE and allows you to setup injectable thread pools on-the-fly.
Each thread pool is created according to sensible conventions and produces an injectable statistics POJO. Not only the configuration, but also all major components are extensible without any additional configuration:
import com.airhacks.porcupine.execution.boundary.Dedicated;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
public class MessagesService {
@Inject
@Dedicated
ExecutorService light;
@Inject
@Dedicated
ExecutorService heavy;
//...
}
The installation is easy:
<dependency>
<groupId>com.airhacks</groupId>
<artifactId>porcupine</artifactId>
<version>NEWEST_VERSION</version>
<scope>compile</scope>
</dependency>
and the dependency small (16 kB).
Enjoy https://github.com/AdamBien/porcupine and see you at workshops.adam-bien.com. Porcupine is heavily discussed during the workshops. Stay in touch with airhacksnews.com!.
Hi,
I have a question about using @Dedicated to inject java.util.concurrent.ExecutorService instance in a @Stateless bean that doesn't expose any javax.ws.rs rest method(s): if i call it from a junit test using CDITestRunner, the threadFactory class injected by container is null (NullPointerException). I suppose ThreadFactoryExposer doesn't produce java.util.concurrent.ThreadFactory outside a application ee container, is it true? Or is it a bug? Thanks
Posted by Roby on March 13, 2018 at 05:46 PM CET #