
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Importance of destroyForcibly() method in Java 9?
The destroyForcibly() method can be used to kill a process. It will be needed if the process has finished or has frozen. For instance, the isAlive() method returns true after destroyForcibly() is called. The destroyForcibly() method returns true if the termination successfully requested, otherwise returns false.
Syntax
boolean destroyForcibly()
In the below example, we will able to launch a notepad application, and it will be terminated after the destroyForcibly() method called.
Example
import java.io.IOException; import java.lang.ProcessBuilder; public class DestroyForciblyTest { public static void main(String args[]) throws IOException, InterruptedException { ProcessBuilder pBuilder = new ProcessBuilder(); pBuilder.command("notepad.exe"); // Start notepad application Process process = pBuilder.start(); System.out.println("Started Notepad Application"); // Sleep for 5 seconds Thread.sleep(5000); // Kill the notepad process.destroyForcibly(); System.out.println("End of Notepad Application"); } }
Output
Started Notepad Application End of Notepad Application
- Related Articles
- Importance of Collectors.flatMapping() method in Java 9?
- Importance of ofInstant() method in Java 9?
- Importance of Thread.onSpinWait() method in Java 9?
- Importance of Optional.or() method in Java 9?
- Importance of the Collectors.filtering() method in Java 9?
- Importance of transferTo() method of InputStream in Java 9?
- Importance of iterate() method of Stream API in Java 9?\n
- Importance of MethodHandles class in Java 9?
- Importance of yield() method in Java?
- Importance of isDaemon() method in Java?
- Importance of clone() method in Java?
- Importance of join() method in Java?\n
- What is the importance of REPL in Java 9?
- Importance of Module Descriptor in a Module in Java 9?
- Importance of the getCause() method in Java?\n

Advertisements