Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9145425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:30:41+00:00 2026-06-17T10:30:41+00:00

I have two ManagedBeans. Concerning my problem, they do the following: First: @ManagedBean public

  • 0

I have two ManagedBeans.

Concerning my problem, they do the following:

First:

@ManagedBean
public class Provider {

    private Event<ProvideEvent> event;

    private static boolean handling = false;
    public provide(@Observes ConsumeEvent consume){
      if(!handling){
        //provide some stuff
        event.fire(new ProvideEvent(ProvidedStuff stuff);
      }
    }
}   

Second:

@ManagedBean
@SessionScoped
public class Consumer {

    private Event<ConsumeEvent> event;

    @PostConstruct
    public void initialize(){
      event.fire(new ConsumeEvent());  
    }

    private static boolean handling = false;
    public consume(@Observes ProvideEvent providedStuff){
      if(!handling){
        //use the provided stuff
      }
    }
}     

This happens, when the website is called:
1. Consumer is instantiated.
2. Consumer fires the event.
3. Provider is instantiated.
4. provide() is called.
5. A NEW CONSUMER IS INSTANTIATED
6. consume() is called.

As you can see, I had to use a boolean “handling” to keep the application from looping infinitly.

Why is the container not using the instantiated SessionScoped ManagedBean? I thought SessionScoped ManagedBeans are like Singleton for the Session?
I guess I could work around this by:
A: Using static variables for the changed properties.
B: Implementing the Observer-Pattern manually.

But there has to be an easier way here!?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:30:42+00:00Added an answer on June 17, 2026 at 10:30 am

    I believe the problem could be that you fire the event in the @PostConstruct method of your Customer.

    From the javadocs:

    This method MUST be invoked before the class is put into service.

    As far as I understand, that results in a race condition. The Provider is probably firing the second event earlier than your Customer instance finishes executing initialize() and the container puts it into service. Hence, it won’t receive the event. I’m too inexperienced with Java EE to give good advice how to prevent that race condition though. I would probably work around it with an ugly SynchronousQueue as a meeting point.

    Additional info: the default with @Observes is to create a new instance of the event receiver if none exists (is in service). That’s why another customer is created. Use @Observes(notifyObserver = Reception.IF_EXISTS) to only notify existing instances that are in service.

    I thought SessionScoped ManagedBeans are like Singleton for the Session?

    No, it just defines the lifetime of the object(s). It doesn’t really enforce session-singleton behavior. The container would probably prefer the existing instance though, if it was in service at the time the second event is fired.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following two simple POJOs: class Person { String name Address address; //and
I have two classes (MVC view model) which inherits from one abstract base class.
I have two columns say Main and Sub . (they can be of same
I have two classes which depend on each other. I've solved this problem before
I have two date fields that I need to join on. The first is
Have two bean definitions: file a.xml <bean id=A class=com.A> <property name=bClass ref=B/> </bean> file
I have two tables imagesgroup and images imagesgroup has following fields id and group_name
I'm running with the following problem. I have a few Managed Beans that are
have two three tables one for student, second for class, and the third for
I have two convex polygons in 3D. They are both flat on different planes,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.