Remember, the container may not manage a pool for stateful bean instances. Stateful beans are always associated with a client. When JNDI lookup (or dependency injection) is performed for a stateful bean, an instance of the stateful bean will be created.

Fu Dong Jia
Ranch Hand

Joined: May 23, 2007
Posts: 131

posted Nov 24, 2008 22:17:00

0

But,what did that? "the client invokes a method, a new Stateful Session Bean is created" OR "When JNDI lookup (or dependency injection) is performed for a stateful bean, an instance of the stateful bean will be created"

Originally posted by Kenneth Lomvey: Remember, the container may not manage a pool for stateful bean instances. Stateful beans are always associated with a client. When JNDI lookup (or dependency injection) is performed for a stateful bean, an instance of the stateful bean will be created.

I guess as per the Specs, a container should not manage a pool for Stateful Session Beans. Please correct me if I'm wrong.

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!

Everytime, the client invokes a method, a new Stateful Session Bean is created. So each time it goes through it's lifecycle.

your explanation certainly not correct

Container will create if client has not a reference. If it create for every method call what is the usefulness of SF over SL. We you SFs when client can't keep his previous status like for http client (But http session would be lightweight, efficient than SFSB in general)

Jothi

I guess as per the Specs, a container should not manage a pool for Stateful Session Beans. Please correct me if I'm wrong.

Container will create if client has not a reference. If it create for every method call what is the usefulness of SF over SL. We you SFs when client can't keep his previous status like for http client (But http session would be lightweight, efficient than SFSB in general)

Chaminda, what do you understand by this line, when i say, when a client invokes a method, SFB is created.

I mean to say here, when everytime the client invokes a first method on SFB for which it has no reference, it creates SFB everytime.

So your this reply turns out to be incorrect response.

your explanation certainly not correct

Container will create if client has not a reference. If it create for every method call what is the usefulness of SF over SL. We you SFs when client can't keep his previous status like for http client (But http session would be lightweight, efficient than SFSB in general)

Jothi

Kenneth Lomvey
Ranch Hand

Joined: Nov 08, 2008
Posts: 94

posted Nov 25, 2008 08:59:00

0

Amandeep,

You are correct by saying...

...when everytime the client invokes a first method on SFB for which it has no reference, it creates SFB everytime.

But, as the second post of this topic, you said...

Everytime, the client invokes a method, a new Stateful Session Bean is created. So each time it goes through it's lifecycle.

You are wrong by this. Because only the first invocation on a SFB (by a client) may create a new instance.

I'm not sure, if it is specified, wether the bean instance is created when "lookup" is called or when the first "addCar" call occurs. Glassfish seems to create the instance with the lookup call.

By the way, you can check if the bean instances are equal by "cc1.equals(cc2);" (see core spec 3.4.5.1)

Hope this helps. [ November 25, 2008: Message edited by: Ralph Jaus ]

SCJP 5 (98%) - SCBCD 5 (98%)

Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 850

posted Nov 25, 2008 12:10:00

0

So that's what i mean, whenever the client is doing lookup, a new SFB instance is created. Right.

So what i meant in previous post's is that, whenever the client invokes the method, a new instance will be created.

See everytime, the addCar method is called, it means a new transaction starts and when i commit in the database, the transaction end's.

SO now you agree, the SFB can have only 1 transaction.

if SFB has only 1 transaction then also it mean's a new intance is created for every new transaction.

So again the new transaction is created only, when the client inokes the method or do lookup for SFB.

Hope this clears!

Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342

posted Nov 25, 2008 12:27:00

0

You're mixing two things:

1. creating a bean instance 2. starting / ending transactions

if SFB has only 1 transaction then also it mean's a new intance is created for every new transaction.

So again the new transaction is created only, when the client inokes the method or do lookup for SFB.

No, that's definitively wrong. In my CarClient example each cc1.addCar(..) call will start a new transaction but will not lead to the creation of a new bean instance: Just insert some println into the constructor of your bean class. The number of outputs will correspond to the number of lookup's not to the number of addCar calls resp. number of performed transactions.

The following steps describe the life cycle of a stateful session bean instance: - A session bean instance's life starts when a client obtains a reference to a stateful session bean instance through dependency injection or JNDI lookup, or when the client invokes a create<METHOD> method on the session bean's home interface. This causes the container to invoke newInstance on the session bean class to create a new session bean instance.

Regards<br />Tomasz Lewandowski<br />SCJP5 (97%) | SCWCD5 (98%)

Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 850

posted Nov 25, 2008 14:35:00

0

this only i meant to say

The following steps describe the life cycle of a stateful session bean instance: - A session bean instance's life starts when a client obtains a reference to a stateful session bean instance through dependency injection or JNDI lookup, or when the client invokes a create<METHOD> method on the session bean's home interface. This causes the container to invoke newInstance on the session bean class to create a new session bean instance.

Fu Dong Jia
Ranch Hand

Joined: May 23, 2007
Posts: 131

posted Nov 25, 2008 18:13:00

0

Thanks everyone!

The following steps describe the life cycle of a stateful session bean instance: - A session bean instance's life starts when a client obtains a reference to a stateful session bean instance through dependency injection or JNDI lookup, or when the client invokes a create<METHOD> method on the session bean's home interface. This causes the container to invoke newInstance on the session bean class to create a new session bean instance.

That to say,when a client obtains a reference to a stateful session bean instance through dependency injection or JNDI lookup,A session bean instance's life starts. But what is that means:"when the client invokes a create<METHOD> method on the session bean's home interface".For ejb3,there has not a home interface.