addShutDownHook { myRessource.close() }; addShutDownHook { plants.each{ plant -> plant.sprinkle()} }); addShutDownHook { lights.each{ light -> light.switchOff()} });
There's only one method to add to org.codehaus.groovy.runtime.DefaultGroovyStaticMethods
public static void addShutDownHook (Object obj, Closure closure) { Runtime.getRuntime().addShutDownHook( new Thread( closure) ); }