3

In a web service environment, I want to make a few independent http calls per each request that my application receives. As these calls are independent, it doesn't make sense to make them serially so I need a sort of concurrency.

To my understanding, it doesn't make sense to carelessly create new threads for each http call. And also, recreating all these threads brings a lot of overhead.

So I think my best option would be to create a FixedThreadPool in a singleton for all http calls and use that across the application.

Is this the best choice?

8
  • Are you using any particular web-server? Most web-servers will do this for you. For instance, Tomcat already has a fixed thread pool, and will allocate threads from that pool for each request. Commented Jan 22, 2011 at 8:51
  • Having a FixedThreadPool (OR any concurrency util) for making Http service call is a huge overkill. Why do you want to perform threading for an operation like this. Commented Jan 22, 2011 at 8:55
  • @doc_180: I'm new to concurrency so please shoot your alternatives. Commented Jan 22, 2011 at 8:58
  • @rodion: I'm using Jetty, and what I observe is that calls are made serially. Commented Jan 22, 2011 at 8:59
  • Hmmm, Tomcat allocating fixed thread pool does not happen in the client side, does it? I believe he is trying to create a Rest Client and wants to make http calls using FixedThreadPool. If its very important, I will use a framework like Spring REST Template to implement my client.) Commented Jan 22, 2011 at 9:01

2 Answers 2

4

You should take a serious look at Akka, and specifically, the Camel support it offers.

Sign up to request clarification or add additional context in comments.

Comments

3

You may want to consider using the AsyncHttpClient AsyncHttpClient library for very easy asynchronous http calls. A good series of blog posts that describes how to use this library is Going Asynchronous using AsyncHttpClient

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.