Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop/terminate java program by pressing Ctrl+C & Ctrl+Alt+Del for window plateform?

I want to terminate my current Java Program's Execution as like,

System.exit(0);

while user press either one of following key-combination from key-board,

 1. Ctrl+C

 2. Ctrl+Alt+Del

I have searched a lot but nothing seems to be correct. if possible then please provide me a fruitful code snippet too.

thank you, :-)

like image 746
Vishal Gajera Avatar asked Apr 01 '26 10:04

Vishal Gajera


1 Answers

Seems you are looking for Shutdown hooks in java

Check this answers to cook your code :) How can I "intercept" Ctrl+C in a CLI application?

like image 101
Amey Jadiye Avatar answered Apr 03 '26 16:04

Amey Jadiye



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!