Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all,
I would like to know about the scope of the context variable.
I create one context variable called Segment
I design my flow as following:
- tJava (set Segment = Segment1) -> tRunJob
- tJava (set Segment = Segment2) -> tRunJob
the Job inside the tRunJob read the context.Segment value to run.
My question is: Do 2 RunJobs work independently with 2 context value or they will share the same context value?
Thanks
I don't understand why that is, it doesn't seem possible to me unless there is something that I am misunderstanding about your job structure. How are you setting the different values before each tRunJob?
Are you passing the entire context into the job in the tRunJob component? If so, at that point it will copy the contents of the context into the child job.
However, it will copy by reference rather than by value. If you are assigning, say, string values then this will be fine. Any assignment with the equals operator will be fine.
If you alter a mutable object in the context, though, then both child jobs will see the alteration.
We use this behaviour to implement a sharedMap that can be passed into and back up from child jobs.
https://www.talendbyexample.com/talend-returning-values-from-subjobs.html
Hi Shong,
I just wonder about the scope of the context variables between 2 runjobs
In my case, I set 2 values for the same context, but run in 2 different runjobs
I worry that they are using the same value.
Hi @PhilHibbs
I set different values for the same context and run with 2 runjobs.
According to your idea, two runjobs will run with different values for string, right?
Actually, 2 runjobs point to the same task.
My purpose is to create a dynamic task which depend upon the input context, and I want to run 2 jobs at the same time.
And YES, I passed the entire context into the job in the tRunJob component
I don't understand why that is, it doesn't seem possible to me unless there is something that I am misunderstanding about your job structure. How are you setting the different values before each tRunJob?
Hello @PhilHibbs
My purpose is to clone the same job into many running jobs
And I use the context to save the segment details.
Actually, in my database, I create a column name 'Segment' to separate data into my collection.
Each clone job will run on a segment.
But I have test with small amount data, and the context save different value on each time we set it.
It mean that 2 running job have different values event we use the same context.