0

We are writing some REST services using Jersey. Our service make some underlying service calls which happens to be dead slow, which results in holding each thread per request for 3-4 seconds. While investigating I came across Asynchronous Pages in .Net which assigns a thread to each request from thread pool and returns the thread to thread pool once I/O operation starts and gets a new thread when I/O operation is finished to do rest of the processing.

Is there anything similar to this exists in Jersey, where we can serve more concurrent connections instead of holding one thread for each connection until it completes. I don't want to POST a request, return a GUID and then keep polling for the status of the request from client, since I don't control client code.

Thanks, GG

GG.
  • 2,835
  • 5
  • 27
  • 34
  • hi this is really basic but good example of how to do it http://stackoverflow.com/a/3143189/169277 – ant Mar 25 '13 at 20:02
  • Ant, This example tells how to run multiple threads/tasks to do multiple things for same request, but it holds 1 thread/connection running on server. We make an underlying service call which take 4-5 sec and parent thread is blocked for that time frame, which reduces number of concurrent connection which can be made with the server. What we want to do is while we make underlying service call, free up the parent thread which can be used to serve another request and when we get response back, resume the thread to process rest of the request. – GG. Mar 26 '13 at 00:58

1 Answers1

1

Take a look at the Atmosphere's Framework, specifically the atmosphere-jersey module that brings asynchronous annotation to Jersey.

Take a look at one of the samples, or read this quick tutorial. Atmosphere's Jersey does exactly what you are looking at, without requiring you to manipulate threads or anything like that. Come to our mailing list in case you need more help.

(I am the Atmosphere Creator and Lead)

halfer
  • 19,824
  • 17
  • 99
  • 186
jfarcand
  • 1,705
  • 9
  • 6
  • Please see this question. Is it possible to implement. http://stackoverflow.com/questions/19706788/jersey-rest-web-service-with-activemq-middleware-integration . Thaks for your time. – Kumar Nov 06 '13 at 06:04