It can be helpful to print a program's process ID (PID) to the logs or to a file so that when it comes time to kill the program, you know which one to kill. The jAWTRobot library allows you to get the PID.
Another option is to enable console input with the jColorLogger library so that you can type commands into the terminal window and your program can respond accordingly. One of those commands can be "exit" and then your program can gracefully close, saving data and settings, closing ports, databases, etc... (rather than being unceremoniously killed by the task manager).