Skip to content

Shutdownhook not firing with native #465

Closed
@rroller

Description

@rroller

Firing off a CTRL C will not call the shutdown hook in the following example when running as native. It will fire when running with java jar

import java.util.concurrent.CountDownLatch;

public class Agent {
    private final CountDownLatch shutdownLatch;

    public Agent() {
        this.shutdownLatch = new CountDownLatch(1);
    }

    public void run() throws InterruptedException {
        System.out.println("Running");

        // Add a shutdown hook
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            shutdown();
        }));

        try {
            shutdownLatch.await();
            System.out.println("Latch released");
        } catch (InterruptedException e) {
            System.out.println("InterruptedException");
        }
    }

    public synchronized void shutdown() {
        System.out.println("Shutdown called");
        shutdownLatch.countDown();
    }

    public static void main(String[] args) throws Exception {
        new Agent().run();
    }
}

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions