Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passivation question

 
Keerthi P
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the spec, what should the container do if a stateful session bean holds a non-null reference to non-serializable object (Socket, for instance) while passivating the bean? Any exception will be thrown?
[ February 15, 2005: Message edited by: Keerthi P ]
 
Binoj Viswanathan
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
A session bean instance wont b passivated if it holds transaction context. Bean will throw exception if its holding a reference to an open socket connection.(system-level classes such as Thread, OutputStream and its subclasses, and Socket are not serializable).

If the variable(which is part of Session Beans conversational State)isn't serializable, then the serialization mechanism will throw an exception when it tries to serialize the variable. To avoid this, you can declare the variable to be transient.


Binoj V
 
Keerthi P
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. But any idea what exception will be thrown?
[ February 16, 2005: Message edited by: Keerthi P ]
 
Subhash Bhushan C
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most probably, the NotSerializableException will be thrown.

P.S -> Will confirm it tomorrow though. I am feeling tooo sleepy today.
 
Keerthi P
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. Here is what the spec has to say:
The spec does not mandate the container to use Java's Serialization for passivating session beans. The container can choose to use it but need not necessarily have to. Of course, Passivation and Serialization are NOT the same because unlike serialization, passivation does not bother to reset 'transient' fields.

Therefore it is upto the container to decide what to do if an instance field in not serializable. The spec does not stipulate any rules regarding this. If such case should arise, the container may log the problem, throw SYSTEM exception and destroy the bean instance. It may also even choose to reset the non-serialiable field to null or whatever during activation. The spec generally discourages the use of such fields. It simply won't be restored.
[ February 16, 2005: Message edited by: Keerthi P ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic