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 7724243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:38:26+00:00 2026-06-01T04:38:26+00:00

I’m implementing a listener class which listens for some events and then processes them.

  • 0

I’m implementing a listener class which listens for some events and then processes them. If processing of this event goes well then this event is never notified again, but in case of any exception event will be again notified to MyBeanImplementation class after some time and it can again try processing it.

Following code works fine but since this event processing may take some time,

1. I want to have multiple listeners.
2. Limit number of calls to service, may be using threadpool.

How can I have multiple listeners which will process each event differently? I’m new to Spring and don’t have much idea if this is even possible or not.

Heres is an example:

// Spring Configuration:

<bean id="MyBean" class="MyBeanImplementation">

// Sample Class

public class MyBeanImplementation implements EventListener {

    @override
    public processEvent(Event event) throws EventProcessFailureException {
        try {
            // Validate event
            validateEvent(event);
            // Call another service to store part of information from this event
            // This service takes some time to return success
            boolean success = makeCallToServiceAndStoreInfo(event);
            if(!success) {
                throw new EventProcessFailureException("Error storing event information!");
            }
        } catch (Exception e) {
            throw new EventProcessFailureException(e);
        }
    }

}

Thanks

  • 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-01T04:38:27+00:00Added an answer on June 1, 2026 at 4:38 am

    Basically, you can use Strategy pattern to introduce different listeners that re-act in a different way to a shared event.

    <bean id="strategy1Listener" />
    <bean id="strategy2Listener" />
    <bean id="strategy3Listener" />
    

    Then, you can introduce a composite listener to iterate through other listeners and pass through the event and allow them to process the event:

    <bean id="compositeStrategyListener">
      <property name="listeners">
        <list>
          <ref bean="strategy1Listener" />
          <ref bean="strategy2Listener" />
          <ref bean="strategy3Listener" />
        </list>
      </property>
    </bean>
    

    On the other side of the story, you have an object that generates/publishes the events:

    <bean id="eventGenerator">
      <property name="eventListener" ref="compositeStrategyListener" />
    </bean>
    

    So, now eventGenerator publishes the generated event to a compositeStrategyListner which iterates over the listeners it has and allows them to process the event in their own different way.

    You can also take advantage of Spring Task Execution to configure how you need to run the task of event processing.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a

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.