JAX-RS Resource Lifecycle Performance Impact

I know that by default, the JAX-RS endpoint life cycle is once per request , so you can enter information specific to the request into the instance.

And we can also make Singleton endpoints, which means once for an application in which the request information cannot be entered into the instance, but can be entered into the requested method.

1. So, I would like to know which approach is better in terms of performance, once per request or once for each application .

2. I would also like to know all the pros and cons of these approaches, other data requiring injection,

3. Which approach do you prefer to use in your applications API

Note. I have used the method "once in a single request" so far, but I am always surprised that it is efficient, definitely simplify it and reuse it.

+2
source share
1 answer

To start with your last question: I always use the default value (on request), and I rarely came to the point where I wanted to change this.

What could be a reason to prefer each other?

  • - (, API), . , . @ApplicationScoped CDI bean .
  • @xxxParam @QueryParam , . . ( @Context).

, . results github, : 1,5%. , . JVisualVM, , , , .

+2

Source: https://habr.com/ru/post/1694812/


All Articles