The destroyForcible() สามารถใช้เพื่อ ฆ่ากระบวนการ . จะมีความจำเป็นหากกระบวนการเสร็จสิ้นหรือถูกแช่แข็ง ตัวอย่างเช่น isAlive() วิธีการคืนค่าจริงหลังจาก destroyForcible() ถูกเรียก. ทำลายบังคับ() method คืนค่า true ถ้าการบอกเลิกสำเร็จ มิฉะนั้นจะคืนค่า false
ไวยากรณ์
boolean destroyForcibly()
ในตัวอย่างด้านล่าง เราจะสามารถเปิด แผ่นจดบันทึก แอปพลิเคชันและจะถูกยกเลิกหลังจาก destroyForcible() วิธีการเรียก
ตัวอย่าง
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");
}
}
ผลลัพธ์
Started Notepad Application End of Notepad Application
