• Post Reply Bookmark Topic Watch Topic
  • New Topic

BMP question

 
sarah Marsh
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I read
http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/BMP4.html#63324
'The SalesRepBean class instantiates the customerIds variable in the setEntityContext method, not in ejbCreate. The container invokes setEntityContext just once--when it creates the bean instance--ensuring that customerIds is instantiated just once. Because the same bean instance can assume different identities during its life cycle, instantiating customerIds in ejbCreate might cause multiple and unnecessary instantiations. '
Why it needs 'ensuring that customerIds is instantiated just once'?
Thanks in advance!
Sarah
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could one possible reason be that the ID is picked from a resource such as a database sequence?
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sarah Marsh:
Why it needs 'ensuring that customerIds is instantiated just once'?

Perhaps to reduce memory and less work for garbage collector?
The values are picked up from database in ejbLoad() and everytime list.clear() method is called to ensure that the previous data is cleared up before storing the new list of customerIds for the current SALESREP entity bean.
Instead of the setEntityContext() method, I think the same ArrayList can also be instantiated in the no-arg public constructor of the bean.
[ December 15, 2003: Message edited by: Vish Kumar ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!