Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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:</p> <ul> <li>Watch out for <code>throws Exception</code> on a method. This hides all sorts of evils. A method should usually enumerate the exceptions that it throws.</li> <li>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.</li> <li>Try to have small try/catch blocks which catch a single exception if possible. Don't inclose huge blocks of code with <code>try { ... } catch (Exception e) { ... }</code>. That, again, hides evils.</li> <li>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...</li> <li>Make sure you are properly reporting <em>all</em> exceptions. Every catch block should do something with the exception. <code>e.printStackTrace()</code> may work but providing more information about the problem is usually in order.</li> </ul> <blockquote> <p>But I don't know how to re-start a stopped thread.</p> </blockquote> <p>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 <code>RabbitMQ</code> connection. Again, it's about proper exception handling. I don't know <code>RabbitMQ</code> but something like the following pseudo code might help:</p> <pre><code>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; } } </code></pre> <p>Best of luck.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload