signals - Interrupt a java application -
i have following problem: run iterative algorithm written in java on workstation. workstation uses sge under hood. each job have set soft , hard time limit. when soft time limit reached, running program receives sigusr1. when hard time limit reached, sigkill instead.
i able handle sigusr1 stopping @ current iteration , writing current solution file. canonical way in c application trap signal in signal handler, set boolean flag checked periodically during iteration , triggers termination.
the java program looks this:
public class testinterrupt { public static volatile boolean shouldterminate = false; public static void main(final string[] args) throws interruptedexception { int = 0; while (++i < 100) { thread.sleep(1000); if(shouldterminate) { break; } } // write data file here. } }
there no signal handlers in java (afaik). wrapped java application in bash script can trap signal. question is, how can notify java application? there standard mechanism this?
i have seen this similar thread revolves around using shutdown handlers. answer accepted. however, far saw (and far api docs tell), shutdown hooks run threads after shutdown has been initiated rather when sigint or similar received, don't see how useful trap signal.
Comments
Post a Comment