3
votes

I have a stateful session bean with the following annotations:

@Stateful
@Name("fooBar")
public class FooBarAction implements FooBar {

I noticed there are 2 ways to get my FooBar instance:

Seam lookup:

Component.getInstance(FooBarAction.class);

JNDI lookup:

(new InitialContext()).lookup("MYAPP/FooBarAction/local");

When I use the JNDI lookup, each time I execute the lookup, I notice a new instance of FooBar is created. The default constructor gets called, and setter methods are used to bring back the state (attributes) of my SFSB.

When I use the Seam lookup, no default constructor is called and no setter methods are called. I just have the instance. The same instance as the previous lookup.

So what's the difference? And what is the best way to use?

1

1 Answers

2
votes

From the doc: This method returns a singleton for the specified component, so calling it twice in a row with the same component name will return the same instance of the component.