Limiting threads used for asynchronous requests - Jersey Client

Jersey Client already has support for making asynchronous requests, but it uses default ExecutorService, which spawns new thread for each request, which is not very convenient in most of cases. You can set your own ExecutorService (see Client.setExecutorService()) and limit thread count but it is not that obvious thing and lots of users are not aware of this possibility.

So I've added another property to ClientConfig class which represents threadpool size of created ExecutorService. See code snippet below:

        ClientConfig cc = new DefaultClientConfig();
        cc.getProperties().put(ClientConfig.PROPERTY_THREADPOOL_SIZE, 10);
        Client c = Client.create(cc);
        AsyncWebResource r = c.asyncResource("http://somehost.tld/resource").build());

And possibility to set your own ExecutorService still remains, so consider this just as some minor improvement/try for visibility gain for this option.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Pavel Bucek

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today