Here’s the translation of the Go code example to Java, with explanations in Markdown format suitable for Hugo:
Sometimes we’d like our Java programs to intelligently handle Unix signals. For example, we might want a server to gracefully shutdown when it receives a SIGTERM, or a command-line tool to stop processing input if it receives a SIGINT. Here’s how to handle signals in Java with threads.
When we run this program it will block waiting for a signal. By typing ctrl-C (which the terminal shows as ^C) we can send a SIGINT signal, causing the program to print INT and then exit.
Note: The sun.misc.Signal and sun.misc.SignalHandler classes are part of Sun’s proprietary API and may not be available in all Java implementations. For a more portable solution, consider using a third-party library like jnr-posix for signal handling.