0

Short version: I want to be able to manually instantiate and control the lifecycle of statefull beans in Wildfly.

Long version:
I have a system that instantiates several different models of a system. These beans are all instantiated as singleton beans so they can keep their state and take inputs as a group. They are always looked up as a group with

@Inject
@Any
Instance<BusinessInterface> businessBeans;

which allows me to pas them all input as a group and collect their data as a group. It also means that I can deploy new singleton beans/models and they get pulled into the workflow dynamically. I don't have any need to ever look up any specific models/beans.

Now, for the problem that anyone with experience sees coming from a mile away: a new requirement means that I need to be able to deploy multiple copies of each model. But they're singletons. Is there a way to make this work? I feel like there must be a way for me to manually instantiate beans that won't die until I kill them, but I can't seem to find it.

Alex N.
  • 654
  • 8
  • 21
  • I presume you didn't mean stateful sessionbeans, but common CDI-beans having instance variables (state). There are (dangerous) ways to instantiate CDI-Beans manually during runtime, but imhO no way to have the businessBeans-collection automatically extended by these manually instantiated beans. – aschoerk Jun 05 '18 at 15:04
  • @aschoerk Can you share? Maybe it will at least point me in the right direction. – Alex N. Jun 05 '18 at 15:06
  • lookup BeanManager.createCreationalContext that should give you more details. But beware memory-leaks can happen – aschoerk Jun 05 '18 at 15:13
  • Perhaps https://stackoverflow.com/questions/8420070/how-to-create-and-destroy-cdi-weld-managed-beans-via-the-beanmanager helps – aschoerk Jun 05 '18 at 15:18

0 Answers0