I would like to create a reusable JAR that I would share across many of my projects. In this JAR, when a certain method is invoked, several threads need to be created.
I'd like to be able to add a shutdown hook (Runtime.addShutdownHook(...)
) that helps these spawned threads shutdown gracefully, but not sure if I can do this from inside a "headless" (no main(String[])
method) JAR.
So I ask: can any method in any JAR access the "main" thread and add a shutdown hook to it? If so, how?