Who killed the My Java Infinite loop thread?

As stated in the header, I have some code wrapped in an infinite loop while(true), and they are all completely caught in tryand blocks catch. However, this thread starts in the main method, but after a long start this workflow disappears mysteriously when I check the use of jstack and impose the accumulated work.

Below is my code:

public void run() {
    while (true) {
        try {
            // Consumer consumes from Kafka server
            Global.KAFKA_METRIC_DATA_CONSUMER.consume(topic, handler);
        } catch (Exception e) {
            logger.error("Kafka consumer process was interrupted by exception!");
        } finally {
            try {
                // Prevent restart too often
                Thread.sleep(30 * BaseConst.SECOND);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

In my opinion, this structure will support the flow that is the consumer. Even if the consumption methods () failed, it will restart endlessly. However, as I mentioned above, the whole thread disappears without any error log. Can someone give some clues please?

Additional information that may be helpful:

  • , . .
  • java, , - , gc . - .
+4
3

OutOfMemoryError . , Throwable.

- consume(topic, handler), , , , 30 ... , .

+9

Exception, , java.lang.Error java.lang.Throwable (, OutOfMemoryError)

, Throwable, Exception .

+1

Your thread is probably killed by mistake.

Error is no exception! But they both expandThrowable

Add another catch block that detects errors.

Throwable should never be caught because errors require a different handling than exceptions

0
source

Source: https://habr.com/ru/post/1617595/


All Articles