Skip to content

Instantly share code, notes, and snippets.

@rainsunny
rainsunny / AppShutdown.java
Created August 11, 2017 12:38
Java application graceful shutdown
ESRunner runner = new ESRunner();
// Gracefully shutdown
final Thread mainThread = Thread.currentThread();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
runner.shutdown(); // Clean up work
mainThread.join(200); // wait main thread to stop
@rainsunny
rainsunny / bash_snipts.sh
Last active August 11, 2017 09:40
bash snipts
##### get current directory in absolute path
# Add `> /dev/null 2>&1` to eliminate outputs of `cd` in some cases
base_dir="$( cd "$(dirname $0)" > /dev/null 2>&1 && pwd)"
# other options
current_dir=$(pwd) # current working directory
base_dir=$(dirname $0) # in relative path