Reactive, Asynchronous JAX-RS Client with Thread Pool aka Bulkheads

A plain Java class with injected and configurable thread pool (ManagedExecutorService):

import java.util.concurrent.CompletionStage;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.enterprise.concurrent.ManagedExecutorService;

public class ContentFetcher {

    private Client client;
    private WebTarget workshopsTarget;
    ManagedExecutorService mes;
    public void initClient() {
        this.client = ClientBuilder.
        this.workshopsTarget ="");

    public CompletionStage<String> fetchContent() {
        return this.workshopsTarget.request().


...used by the asynchronous, reactive invoker (the method rx()).

Can be directly exposed via an ordinary JAX-RS resource:

public class WorkshopsResource {

    ContentFetcher fetcher;

    public CompletionStage<String> content() {
        return this.fetcher.fetchContent();


The amount of parallelism is globally configurable with the default ManagedExecutorService, or by declaring dedicated ManagedExecutorService (effectively Bulkhead pattern, also covered in workshop) for each communication / IO channel.

See you at Web, MicroProfile and Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home:

Web Apps, SPA, PWA with vanilla Java Script (ES 6+), CSS 3 and WebStandards only. As simple as possible, but not simpler. See you at: (Progressive) Web apps, Single Page Apps and WebStandards airhacks workshops at MUC airport, Winter Edition the podcast:

Stay in touch:


Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments