I have a Talend process with an infinite loop. I'd love to replace this infinite loop with a more controllable "while" loop. My thought is to have the while loop monitor an internal variable (maybe a context variable?) and set this variable once a Unix SIGINT signal is caught.
Is this possible? If yes how?
Are there viable alternatives? I could work with a sentinel file and stop the process if that file is found on disk but the SIGINT handling would be cleaner.
Technically the Talend process is a Java application, and I could potentially use a custon tJava component to write Java code to handle this properly.
update
I have tried to add a shutdown hook using a tJava component:
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.out.println("Signal caught... finishing up current work and exiting.");
context.keepRunning = false;
}
});
In this component I am setting context.keepRunning, which is my loop condition to false.
Unfortunately, this not only runs the content in the shutdown hook, but also immediately exits the process. Control is not given back to the Talend process. I have two tWarn component after the loop component. One onSubjobOk and one on onSubjobError. Neither one is executed after sending a SIGINT or SIGTERM signal. Yet the println statement from the shutdown hook is executed.