This somehow got lost in my mailbox, so just seeing it now.
We did not end up using the JVM shutdown hook because it turned out it did not satisfy our use case. We needed resources to be released in a certain order, and these JVM shutdown hooks do not guarantee that.
STORM-183 attempted to make the storm shutdown hooks happen by having the supervisor first asking the worker to quit before killing the worker.
It is on master branch, and should be available with the 0.9.3 release. -- Derek On 8/18/14 8:39, Spico Florin wrote:
Hello! I've followed the suggestion of adding a shutdown hook inside the Bolt as it was suggested by this post http://grokbase.com/t/gg/storm-user/136ks2tgmn/how-do-you-perform-cleanup-when-killing-a-topology (see Derek's). The hook is initialized, but the run method is not called when the topology is killed. Please advice. Thanks. Florin Find bellow a shortened version of the code : public void prepare() { CleanupShutdownHook hook = new CleanupShutdownHook(); hook.attachShutDownHook(); csvWriter = new CSVWriter(new BufferedWriter(new FileWriter("myFile"))); } public void cleanup() { csvWriter.close() } } public class CleanupShutdownHook { public void attachShutDownHook() { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { cleanup(); } }); } } On Mon, Aug 18, 2014 at 3:12 PM, Spico Florin <spicoflo...@gmail.com <mailto:spicoflo...@gmail.com>> wrote: Hello! I'm using the storm version 0.9.2 incubating. I have a CSV file is initialized in the prepare method of a BaseBasicBolt prepare() { csvWriter = new CSVWriter(new BufferedWriter(new FileWriter("myFile"))); } and I would like to close it when I kill the topology public void cleanup() { csvWriter.close() } I have observed that when I was shutting down the Local cluster by calling the LocalCluster shutdown method, the cleanup method was called. But, when I kill the topology the cleanup method is not called anymore. Can you please advice on how to properly close the resources when killing the topology? I look forward for your answers. Regards, Florin