Can a VM die when a catch exception occurs consecutively?

Asked 1 years ago, Updated 1 years ago, 72 views

Could a VM die because of an estimated 5 catches exceptions per second?

Since it is a caught exception, it is a code covered by try-catch, and all you do in catch is to log at the error level. There's someone's argument that this is killing the VM, and I wonder if that's possible.

Problems with logging itself: Exclude reasons such as not being able to create a file or running out of storage space.

Summarize the code very simply:

import org.joda.time.LocalDateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class VMStressTest {
    private static final Logger logger = LoggerFactory.getLogger(VMStressTest.class);
    public static LocalDateTime current = LocalDateTime.now();

    public static void main(String[] args) {
        LocalDateTime begin = LocalDateTime.now();
        LocalDateTime end = begin.plusMinutes(1);

        Runner runner = new Runner();
        while (current.isBefore(end)) {
            refresh();
            try {
                runner.ticktack(current.getSecondOfMinute());
            } } catch (Exception e) {
                logger.error(e.getMessage(), e);
//              logger.debug ("There's an error?"");
            }
        }
        logger.info ("End");
    }

    private static void refresh() {
        current = LocalDateTime.now();
    }

    private static class Runner {
        private static final Logger logger = LoggerFactory.getLogger(VMStressTest.Runner.class);
        private int prevSec;

        public void ticktack(int currentSec) {
            if (currentSec != prevSec) {
                this.prevSec = currentSec;
                logger.debug("{}", currentSec);
            } } else {
                int nan = 1 / 0; // = throw new ArithmeticException();
            }
        }
    }
}

It looks like this, but no matter how you look at it, it doesn't look like it's going to kill VM, right?
Is there anything I overlook?

java jvm exception

2022-09-21 11:46

1 Answers

Is dying a crash? The exception does not cause a crash.

With many exceptions, if jvm is killed, it should be considered a bug.

And when jvm crashes, it creates a core dump or hs_err_pid.

If you analyze the file, you can find out the cause.


2022-09-21 11:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.