0

I am working on an application with several SFSB all implementing the same interface.

To decide at runtime, whiche concrete implementation to use, I have following Factory Method:

@SuppressWarnings("rawtypes")
@Inject @Any Instance<SFSBInterface> sfsbSource;

public <T> SFSBInterface<T> initBeanForm(Class<T> clazz, Class<? extends SFSBInterface<T>> sfsbClass, Annotation... qualifiers) {
    SFSBInterface<T> sfsb = sfsbSource.select(sfsbClass, qualifiers).get();
    return sfsb;
}

Each concrete implementation does have a @Remove annotated method implemented. Now I have a case, where I want to remove this sfsb and get a new Instance at calling this method.

I am calling the remove method and delete all references to this object, but the instance keeps being in memory. When I now ask for an instance of this class, I am getting the same instance, for which I called the remove before.

My questions are:

  1. Do I run into problems, if I use this instance, for which I called the remove method?
  2. Is it normal that the removed instance keeps in memory?
  3. How can I effectively remove this instance?
  4. How can I obtain a real new instance of my class?

Kind regards Christian

BTW: I am using JBoss 7.1.1 and Weld

Christian
  • 3,503
  • 1
  • 26
  • 47

1 Answers1

0

When I now ask for an instance of this class, I am getting the same instance, for which I called the remove before.

I would say that this behaviour is beyond the spec and as such highly vendor-dependent. New beans can be taken from a pool of old instances (this seems to be the case here) or created newly. This strategy can (theoretically) change with new releases of your app-server, and even worse: from environment to environment.

A central question is how you determine that it is a "new instance"?

I reckon that it's not easy to answer if you can live with it or not.

What you should do as a next step is inspecting the lifecycle-hooks of the new bean. If everything is called and all dependencies are injected correctly it looks pretty good IMHO.

Otherwise feel free to update the question :)

Jan Groth
  • 14,039
  • 5
  • 40
  • 55