Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

kill the entire job when sub job dies - multi thread enabled

Hi!
Question: How do you kill the entire job when one of its sub jobs has died - multi thread enabled on the parent job?
Specifics (please bear with me):
* Created Job A that executes a java code which listens for a flag to terminate the job. When the flag it listens for is 'yes' then it outputs the flag to a tBufferOutput for the parent job to consume.
* Created Job B - a simple job that sleeps for 10 secs and write some output to file.
* Created Parent Job - added Job A and Job B. Job A outputs the flag to a BufferOutput for the grandparent job to consume. Parent job is checked to run multi thread.
* Created Grandparent Job - added Parent Job. Parent Job outputs the flag to tDie Component.
Execution:
* Run Grandparent Job.
* It will call Parent Job and in turn call Job A and Job B in separate threads.
* Job A will listen for the flag and wait while Job B is running.
* Before Job B 'wakes up' from sleep, I pass the flag to terminate the job.
* Job A receives the flag and pass the flag all the way back up the Grandparent Job.
* PROBLEM: I can see "the end is near" message from the tDie in the console, so I know it did call tDie. However, it doesn't kill the job until Job B is complete. Ideally, I want to terminate Job B as well. I thought by passing the flag to the grandparent, it will terminate everything.

Please help.
Labels (3)
4 Replies
Anonymous
Not applicable
Author

Hello
There are two ways can achieve your request:
1)Check 'Exit the jvm immediately' option on tDie component, the Job B will aslo stop once the jvm exits(see pic1), but it will brings an nagative impact, when you export the job and deploy it to tomcat as web Service, it will aslo stop the tomcat server once the jvm exits.
2)Don't use tDie component and write java code on tJava to stop the thread of Job B, see pic 2-4.
code on tJava_2
Thread thread = (Thread)globalMap.get("thread2");
thread.stop();
runningThreadCount.add(-1);

code on tJavaFlex_1
 globalMap.put("thread2", Thread.currentThread());

Best regards
shong
Anonymous
Not applicable
Author

Cool, thanks I will give it a try. Although I did try checking the exit jvm in tDie component and it did not exit until job B is done. Anyway, will give the 2nd option a try!
Anonymous
Not applicable
Author

Shong, it worked well thanks! I have couple follow up questions:
1) Is there a way to have Job A to be the first thread to fire off?
2) By stopping/interruping the thread - what would happen to the underlying processes, especially, sql query still running.
Anonymous
Not applicable
Author

Hi Shong, 
I know it a little bit late for this question but when you say "thread2" are you referring to tRunJob? What I want is to kill the query it self during MSSqlOutput commit? I am using Talend Open Studio. Is it possible to stop the commit during run time? 
Thanks.