akonsu akonsu - 1 month ago 17
Java Question

jersey 2: how singleton resources are used?

I read Jersey documentation and did not find an answer to a simple question: when I create a singleton resource, how is it used to serve requests?

When serving requests by a singleton resource, does Jersey queue requests and access the singleton instance for each request synchronously, or does Jersey access the same singleton instance concurrently?

Answer

It's access concurrently, so you should make sure that if you want to use a singleton, that the resource class is thread-safe, and any request scope services injected (by field or constructor) are proxied

Comments