0

We have a use case that a single request from end user will trigger 1 or more http requests to other remote systems. All responses from remote systems will be aggregated into one single response to end user. We had this by using commonj workmanager in websphere.

Now, we want to use asyncHttpClient in order to have lesser threads to service multiple concurrent http calls.

So my question is:

How to integrate asyncHttpClient with commonj workmanager? We have to use commonj as thread pool as it's the only way to have managed threads in wehsphere.

Please advise.

Ken Tsang
  • 61
  • 5

1 Answers1

1

All you need to do is create a new ExecutorService that leverages the work manager as shown below. More details...

  1. Lookup the WorkManager and construct the WASThreadFactory

    InitialContext ctx = new InitialContext(); WorkManager wm = (WorkManager)ctx.lookup("java:comp/env/wm/default"); ThreadFactory tf = new WASThreadFactory(wm);

  2. Create a ThreadPoolExecutor using a bounded buffer

    BlockingQueue q = new ArrayBlockingQueue(50); ExecutorService myOwnThreadPool= = new ThreadPoolExecutor( 1, 10, 5000, TimeUnit.MILLISECONDS, q, tf);

  3. According to their documentation, you can specify the ExecutorService to be used as below

    Builder builder = new AsyncHttpClientConfig.Builder(); builder.setExecutorService(myOwnThreadPool); AsyncHttpClient client = new AsyncHttpClient(builder.build());

NOTE: Didn't verify for compilation. I've however used this in my earlier project.

Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327