test/jdk/jdk/jfr/api/consumer/streaming/TestJVMExit.java
changeset 59246 fcad92f425c5
parent 59226 a0f39cc47387
equal deleted inserted replaced
59245:de882051f7a5 59246:fcad92f425c5
    40  * @run main/othervm jdk.jfr.api.consumer.streaming.TestJVMExit
    40  * @run main/othervm jdk.jfr.api.consumer.streaming.TestJVMExit
    41  */
    41  */
    42 public class TestJVMExit {
    42 public class TestJVMExit {
    43 
    43 
    44     public static void main(String... args) throws Exception {
    44     public static void main(String... args) throws Exception {
    45         TestProcess process = new TestProcess("exit-application");
    45         try (TestProcess process = new TestProcess("exit-application")) {
    46         AtomicInteger eventCounter = new AtomicInteger();
    46             AtomicInteger eventCounter = new AtomicInteger();
    47         try (EventStream es = EventStream.openRepository(process.getRepository())) {
    47             try (EventStream es = EventStream.openRepository(process.getRepository())) {
    48             // Start from first event in repository
    48                 // Start from first event in repository
    49             es.setStartTime(Instant.EPOCH);
    49                 es.setStartTime(Instant.EPOCH);
    50             es.onEvent(e -> {
    50                 es.onEvent(e -> {
    51                 if (eventCounter.incrementAndGet() == TestProcess.NUMBER_OF_EVENTS) {
    51                     if (eventCounter.incrementAndGet() == TestProcess.NUMBER_OF_EVENTS) {
    52                     process.exit();
    52                         process.exit();
    53                 }
    53                     }
    54             });
    54                 });
    55             es.start();
    55                 es.start();
       
    56             }
    56         }
    57         }
    57     }
    58     }
    58 }
    59 }