java - Stateless and Stateful confusing definitions and outputs (contradicting to my view) -


from understand @stateless means state of every encountering of client server starting scratch, , @stateful means server saves in memory client's data.
("stateless means there no memory of past. every transaction performed if being done first time.
statefull means there memory of past. previous transactions remembered , may affect current transaction.
").

i have been reading http://www.tutorialspoint.com/ejb/ejb_stateless_beans.htm , http://www.tutorialspoint.com/ejb/ejb_stateful_beans.htm.
examples there show in @stateless annotation, when client exits , re-enters, seems if server did save data , presented books added "previous" client, in @stateful annotation seems if server treated returning client new one, , didn't save list client created.

i assume misunderstanding has misunderstanding of terms "state", "memory" or "transaction", @ moment, confused definition seems contradicting outputs.

you have understanding of difference between stateful , stateless session beans. happened read confusing example.

stateless

stateless session beans managed ejb container spawns pool of instances. can have instance variables in them cannot rely on because server not guarantee hit same instance between method calls.

in stateless example, adding books bookshelf list not idea because second lookup may return different bean instance pool , possible not find book added in first step.

it's explained @ bottom of article :

output shown above may vary depending upon how many stateless ejb object jboss maintaining.

in case single stateless ejb object maintained, may see same list of books after each lookup.

ejb container may return same stateless ejb object every lookup.

stateless ejb bean keeping value of instance variable till server not restarted.

the author understands how stateless session beans work, use case confusing many "may". not recommended store instance variables in stateless session beans since have no guarantee on instance in pool.

stateful

on other hand, stateful session beans bound client after lookup. client keep hitting same instance in ejb container long keeps reference instance got after lookup. last part important because if client lookup, instance of stateful session bean.

in second example, after adding book , displaying how many have, it's normal have 1. second lookup give instance, hence bookshelf empty.

stateful session beans useful store state on server side, careful keep instance reference on client's side.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -