Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Scope of context

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

Labels (2)
1 Solution

Accepted Solutions
PhilHibbs
Creator II
Creator II

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?

View solution in original post

6 Replies
Anonymous
Not applicable
Author

Hi
The scope of context variable is limited to job ltself.
If you need to pass a value from main job to child job, see
https://community.talend.com/t5/Design-and-Development/Passing-a-value-from-a-parent-Job-to-a-child-...
If you need to pass a value from child job to main job, see
https://help.talend.com/reader/5yL32YJ~dV3jlU9Hq_f13g/P1wOw73mm2DjbUKGGuLdjg

Regards
Shong
PhilHibbs
Creator II
Creator II

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

Anonymous
Not applicable
Author

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.

Anonymous
Not applicable
Author

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

 

PhilHibbs
Creator II
Creator II

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?

Anonymous
Not applicable
Author

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.