My simplified job look like this:
tSetGlobalVar--->(onSubJobOK)--->tRunJob--->(onSubJobOK)--->tJava
myKey:"firstValue"
((String)globalMap.get("myKey")): "newValue"
also tried this:
"myKey": "newValue"
System.out.println(((String)globalMap.get("myKey")));
Actual output: firstValue
Expected output: newValue
Is there any other way to modify the value of a global variable in a subjob and get the updated value in the master job ?
In Talend you can pass context variables to subjobs and they work like standard Java variables, so if you pass something unmodifiable (like Strings or basic types) you won't get any change back, but if you pass "by reference" types you will get your object changed and you will see the changes made by the subjob as the father job still holds the reference to the changed object.
So the solution to your problem is to simply pass the globalMap from the Father job to the child job, so the child can read and change that map and the father job will see any change. The map you pass will be a different map than the globalMap of the child job and will be used only where you use it.
Unfortunately Talend have only one "by reference" type: the Object type, so you will need to pass anything as object anc cast it back where you will use it, but I think that is not such a big problem.
Here are the images for the job: Running the father
Passing the map to the child
The child retrieves the map from the contex variable and uses the map