O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Managing the spawned process

There are a few methods, such as destroy(), destroyForcibly() (added in Java 8), isAlive() (added in Java 8), and supportsNormalTermination() (added in Java 9), which can be used to control the process spawned. These methods are available on the Process object as well as on the ProcessHandle object. Here, controlling would be just to check if the process is alive and if yes, then destroy the process. 

In this recipe, we will spawn a long running process and do the following:

  • Check for its liveliness
  • Check if it can be stopped normally, that is, depending on the platform, the process has to be stopped by just using destroy or by using force destroy
  • Stop the process

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required