There's a Safari on-line e-book available for java RESTful services

RESTful Java with JAX-RS is available for reading online.

Strategies for long queries and RESTful services

I was thinking of adding a ConcurrentHashMap/AtomicInterger to a given service for very get requests.

The idea and strategy is this:

  1. For requests we think might take a long time, we start a new Asynchronous query. These requests shouldn't be requests that are performed very often. This query is assigned a new AtomicInteger.
  2. When the query executes, we set a timer, maybe 10 seconds. If the query finishes, we just return the result like normal.
  3. If the query doesn't finish, however, we create a new AsyncQueryStatus object and added to the ConcurrentHashMap with the key being the AtomicInteger. We then return that status object.
  4. The client can poll to a new REST resource which corresponds to the ConcurrentHashMap for status. While the query is still executing, the same status will be returned.
  5. When the query is finished, the status in the ConcurrentHashMap is updated and the original object is added.
  6. The client gets the result on the next polling.

Just some thoughts.

  • No labels