java - RESTful web service life cycle is *always* per request? -
in beginning java ee 7 antonio goncalves written:
in section writing restful web services -> life cycle , callback:
thus, life cycle of restful web service per request service not have worry concurrency , can use instance variables safely.
yet couple lines later writes:
remember restful web service can annotated @stateless or @singleton benefit services of session beans.
so it? lifecycle per request or can session too?
in addition that, if life cycle session, how handle @context
annotation when injecting httpheaders
attribute? headers vary during session, attribute updated after each request?
according jax-rs specification, every implementation (like jersey) must support per-request behaviour:
3.1.1 lifecycle , environment
by default new resource class instance created each request resource. first constructor (see section 3.1.2) called, requested dependencies injected (see section 3.2), appropriate method (see section 3.3) invoked , object made available garbage collection.
an implementation may offer other resource class lifecycles, mechanisms specifying these outside scope of specification. e.g. implementation based on inversion-of-control framework may support of lifecycle options provided framework.
this means if resource class not additionally annotated, per-request. 1 well-known exception spring beans: if rest resource spring bean, spring specifies lifecycle of class. same ejbs (@singleton)
Comments
Post a Comment