Featured post
java - multi threaded servlet; single threaded ejb -
in traditional n tier web app servlets web layer , ejbs(2.0) biz layer, rationale behind making servlet model multi threaded , ejb model single threaded?
i.e there 1 servlet instance requests, ejbs, each request, there new bean instance assigned bean pool.
there indeed 1 instance specific servlet
since supposed stateless. in practice isn't case, it.
there multiple instances of stateless session beans
(slsb), , pooled.
by definition, stateless session beans
stateless, on surface seems paradox. things while stateless session beans
stateless respect individual calls being made them, in fact have state.
this state in form of references other resources. jpa entity manager
, not thread-safe, prime example here. during single call stateless session bean
, caller must have exclusive access resource. when call returns, next caller can have exclusive access, etc.
if single instance used, either callers have wait on each other (which of course killing performance), or have access single instance concurrently. in latter case, bean implementor has manual locking of non thread-safe resources entity manager
brittle, error-prone , in end still causes callers wait on each other.
so, in order improve performance , still have safety guarantee, multiple instances being used.
those instances being pooled , re-used instead of created fresh each request, because finding, initializing , injecting required dependencies of bean can potentially time consuming.
all of automatically means if inject entity manager or other non thread-safe resource servlet (which allowed), may run problems. small loop-hole in java ee architecture, of course worked around making use of stateless session beans.
- Get link
- X
- Other Apps
Comments
Post a Comment