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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:18:43+00:00 2026-05-31T18:18:43+00:00

I am trying to listen to RabbitMQ queue by polling it. But somehow due

  • 0

I am trying to listen to RabbitMQ queue by polling it. But somehow due to network issues if once connection to queue is lost then thread silently dies off and connection and everything is closed. But this is a background task and we wont know untill queue really grows huge and start send out notification.

Can some one please help me with graceful shutdown of thread (which I guess I am already doing by dealing carefully with exception in catch clause). But I don’t know how to re-start a stopped thread.

Is there a way through which I can restart a new instance of stopped thread.

PS: I am instantiating the thread using @postconstruct and calling init thread soon after container loads all beans.

  • 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-05-31T18:18:45+00:00Added an answer on May 31, 2026 at 6:18 pm

    This sounds to me that you are not doing proper exception handling. You say “thread silently dies off” but that doesn’t happen in Java. I would audit your exceptions and watch for the following problems:

    • Watch out for throws Exception on a method. This hides all sorts of evils. A method should usually enumerate the exceptions that it throws.
    • If an Exception throws too many different types of exceptions then that is a signal that it is too large. Consider splitting it into multiple smaller methods. Or handle the specific exceptions inside of the method and throw one exception out.
    • Try to have small try/catch blocks which catch a single exception if possible. Don’t inclose huge blocks of code with try { ... } catch (Exception e) { ... }. That, again, hides evils.
    • If you catch an exception, make sure you aren’t just blindly continuing. If this is a background thread then maybe it should exit or restart the socket or…
    • Make sure you are properly reporting all exceptions. Every catch block should do something with the exception. e.printStackTrace() may work but providing more information about the problem is usually in order.

    But I don’t know how to re-start a stopped thread.

    You do not re-start a stopped thread, you start another one. If the thread should not be shutting down at all then it needs to re-open a socket or maybe re-start its RabbitMQ connection. Again, it’s about proper exception handling. I don’t know RabbitMQ but something like the following pseudo code might help:

    public void run() {
        while (!shutdown) {
           Connection conn = null;
           try {
               conn = rabbitMq.start();
               processQueue(conn);
           } catch (IOException e) {
               // TODO: log the exception here
           } finally {
               // make sure we close the connection
               if (conn != null) { conn.close(); }
           }
           try {
              // we sleep here to not spin if the RabbitMQ host goes down
              Thread.sleep(1000);
           } catch (InterruptedException e) {
              Thread.currentThread.interrupt();
              // bail if someone interrupts us
              return;
           }
    }
    

    Best of luck.

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

Sidebar

Related Questions

I am trying to implement a queue thread that listen to some messages. What
I am trying to set up RabbitMQ rpc. I want one queue to listen,
I'm trying to listen for a client socket connection, so every user to have
I am trying to build a Python deamon which listen to a queue (Redis
I am trying to listen on two devices with libpcap but I still cant
I'm trying to listen to oninput event, but something is wrong with Opera: document.getElementById(i1).oninput
I am trying to listen for UIMenuController Notification in iphone sdk 3.0 . But
I am trying to listen tab-in tab-out action for my swing gui that is
I've been trying to listen for changes in the status bar height – such
I'm trying to find the correct event to listen for that will ensure that

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.