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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:54:40+00:00 2026-06-02T17:54:40+00:00

I am using jboss5.1, EJB3.0 and standalone java application as a ‘subscriber’ I have

  • 0

I am using jboss5.1, EJB3.0 and standalone java application as a ‘subscriber’

I have mechanism which publish messages via jms Topic to subscribers.
when subscriber get the message it need to do few operations until it will start listening again for a future messages.

the problem is that if a subscriber get a message from the Topic it will need to get back fast enough to listen for further messages(else it will miss it in a case another message will be published)

So my solution is to putThread.sleep() for couple of seconds inside the ejb publisher.

This way ill make sure that all subscribers went back to listen before a new message will be published.

I know that using Thread inside EJB’S is not recommended.

any solution for that scenario?

thanks,
ray.

  • 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-02T17:54:41+00:00Added an answer on June 2, 2026 at 5:54 pm

    OK, so your problem is actually that you stop listening to the JMS queue when you process a message and then you register yourself back. Of course, you could then miss messages while your processing a previous one.

    I would suggest to never unregister yourself from the JMS queue and in order to ensure that you process a single message at a time, you could use a single thread pool where you push your processing.

    For example, if previously you had something like this:

    public void onNewJMSMessage(JMSMessage message) {
        unregisterMySelf();
        processMessage(message);
        registerMySelf();
    }
    

    Use this instead:

    Initiate a class member like this:

    private ExecutorsService processingPool = Executors.newSingleThreadExecutor();
    

    and

    public void onNewJMSMessage(final JMSMessage message) {
        processingPool.submit(new Runnable() {
    
             @Override
             public void run() {
                  processMessage(message);
             }
        });
    }
    

    This will guarantee that only a single message at a time is processed (if the enclosing class is unique, otherwise you will have to setup a singleton to ensure the uniqueness of the Single-thread pool).

    Having done that, this will mainly allow you to remove that Thread.sleep in your EJB which is evil and sources of all kind of headaches.

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

Sidebar

Related Questions

I have a Java EE web application using features from the Java EE 6
I'm trying to implement stateless session bean ejb3 in jboss5 using netbeans6.8 as a
I am using restEasy(Restful implementation for jboss) ejb3.0, Jboss5.1.1 AS I did restful service
I have legacy application using struts & ejb2.0 , hibernate v3.0 running on JBoss
We have a web application using the following technologies: JSF 2.0, EJB 3.1, JPA
While I was deploying my application in JBoss5.1.0.GA, I have removed the hsqldb-ds from
Using jboss5.1.x, ejb3.0 This was driving me crazy for two day now: I am
I am using Jboss5.1.x , EJB3.0 I am trying to configure Quartz. I get
I am using Jboss5.1.x, EJB3.0 I am into this subject for couple of days
I am using JBoss5.1.x AS, EJB3.0. I am trying to add a job (using

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.