summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-05-07 11:37:52 +0200
committerPeter Wu <peter@lekensteyn.nl>2014-05-07 11:37:52 +0200
commiteb278af8186496a6517bb1d27b7210bd173841fd (patch)
treea7c86070135f1653b8b37bf6b2d5c79b196bc301
parent10206992c4d279c6460c1c44127f9450662cc05c (diff)
downloadTwitterDataAnalytics-eb278af8186496a6517bb1d27b7210bd173841fd.tar.gz
Shutdown hook for safely closing files
-rw-r--r--src/main/TweetShell.java8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/main/TweetShell.java b/src/main/TweetShell.java
index 4ba50f3..231007f 100644
--- a/src/main/TweetShell.java
+++ b/src/main/TweetShell.java
@@ -49,6 +49,14 @@ public class TweetShell implements TwitterApi.PinSupplier {
// and something that prints tweets to console.
resultListeners.register(new StreamHandler());
// see getPossibleTargets() for more listener types.
+
+ // register shutdown listener to prevent corruption on SIGINT
+ Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
+ @Override
+ public void run() {
+ safeClose();
+ }
+ }));
}
private TwitterApi getApi() throws IOException {