<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Shared variable between 2 jobs in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Shared-variable-between-2-jobs/m-p/2301464#M73570</link>
    <description>Yes the whole thing is annoying and completely non-intuitive the way they have designed it. 
&lt;BR /&gt;Create yourself a Routine with a static map member and just read/write from that. Shared classloader will ensure that all jobs/subjobs in one job access the same data. No clicking on buttons and moving variables around etc. i.e. you just do: MyRoutine.set(varname,value) and MyRoutine.get(varname)</description>
    <pubDate>Tue, 03 May 2016 18:28:45 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-05-03T18:28:45Z</dc:date>
    <item>
      <title>Shared variable between 2 jobs</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Shared-variable-between-2-jobs/m-p/2301460#M73566</link>
      <description>Why does this simple thing seem impossible?&lt;BR /&gt;a) I have a PARENT job that calls SUBJOB1, then SUBJOB2 after SUBJOB1 is done&lt;BR /&gt;&lt;BR /&gt;b) All 3 jobs share the same context with a context variable called "listOfThings" initialized to blank&lt;BR /&gt;&lt;BR /&gt;c) SUBJOB1 appends data to the "listOfThings" context variable.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;d) When SUBJOB2 reads "listOfThings", it is blank&lt;BR /&gt;&lt;BR /&gt;e) I tried this with "globalMap" as well to no avail, it appears "globalMap" is only global to the current job and re-created for every job and hence has no data in it on SUBJOB2&lt;BR /&gt;&lt;BR /&gt;f) If &amp;nbsp;context var "listOfThings" is initialized to "1" this value is available to all subjobs, HOWEVER if any subjob mutates this context variable, that mutation does not carry over to subsequent subjobs that are executed.&lt;BR /&gt;&lt;BR /&gt;This just seems like a very simple thing to me, to allow multiple jobs to interact with one another via some sort of thread-local variable or true "global" variables that span a job and any subjobs it invokes.&lt;BR /&gt;Confused and in need of a solution to this.</description>
      <pubDate>Mon, 02 May 2016 18:56:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Shared-variable-between-2-jobs/m-p/2301460#M73566</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-05-02T18:56:24Z</dc:date>
    </item>
    <item>
      <title>Re: Shared variable between 2 jobs</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Shared-variable-between-2-jobs/m-p/2301461#M73567</link>
      <description>Here's one approach that you can take.&lt;BR /&gt;&lt;A href="http://www.talendbyexample.com/talend-returning-values-from-subjobs.html" rel="nofollow noopener noreferrer"&gt;http://www.talendbyexample.com/talend-returning-values-from-subjobs.html&lt;/A&gt;&lt;BR /&gt;See the section "Returning Values through Context"</description>
      <pubDate>Tue, 03 May 2016 09:58:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Shared-variable-between-2-jobs/m-p/2301461#M73567</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-05-03T09:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: Shared variable between 2 jobs</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Shared-variable-between-2-jobs/m-p/2301462#M73568</link>
      <description>Simplest solution seems to be just create a "routine" backed with a ConcurrentHashMap that exposes get/put methods. Since an entire job is in the same Classloader this static instance is available to all jobs in the process.</description>
      <pubDate>Tue, 03 May 2016 14:58:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Shared-variable-between-2-jobs/m-p/2301462#M73568</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-05-03T14:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Shared variable between 2 jobs</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Shared-variable-between-2-jobs/m-p/2301463#M73569</link>
      <description>Context variables and globalMap variables are only available to components inside individual jobs automatically. You can send then to child jobs (as I guess you are aware) pretty easily, but sending the values back to the parent is not so nice. The way they work makes sense (ie changing them in child jobs not automatically changing them in parent jobs), but it is annoying having to manually pass the values back if you want the values to change with the child jobs.&amp;nbsp;
&lt;BR /&gt;Your solution (the ConcurrentHashMap) is what I use if I need to do this. I think it could be handled in a better way by having an option on the tRunJob component to allow the contexts that are sent to the job to be passed back to the parent. Maybe this could be an enhancement Talend?</description>
      <pubDate>Tue, 03 May 2016 17:57:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Shared-variable-between-2-jobs/m-p/2301463#M73569</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-05-03T17:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: Shared variable between 2 jobs</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Shared-variable-between-2-jobs/m-p/2301464#M73570</link>
      <description>Yes the whole thing is annoying and completely non-intuitive the way they have designed it. 
&lt;BR /&gt;Create yourself a Routine with a static map member and just read/write from that. Shared classloader will ensure that all jobs/subjobs in one job access the same data. No clicking on buttons and moving variables around etc. i.e. you just do: MyRoutine.set(varname,value) and MyRoutine.get(varname)</description>
      <pubDate>Tue, 03 May 2016 18:28:45 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Shared-variable-between-2-jobs/m-p/2301464#M73570</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-05-03T18:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: Shared variable between 2 jobs</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Shared-variable-between-2-jobs/m-p/2301465#M73571</link>
      <description>&lt;P&gt;Hello:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you provide example of this concurrentHashMap routine with get / set methods?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 23:14:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Shared-variable-between-2-jobs/m-p/2301465#M73571</guid>
      <dc:creator>swambulkar</dc:creator>
      <dc:date>2018-06-12T23:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: Shared variable between 2 jobs</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Shared-variable-between-2-jobs/m-p/2301466#M73572</link>
      <description>&lt;P&gt;Create a new Routine (under code in the repository list), call it UniversalMap, and paste this in there:&lt;/P&gt;&lt;PRE&gt;package routines;

import java.util.concurrent.ConcurrentHashMap;

public class UniversalMap {

    private static ConcurrentHashMap&amp;lt;String, Object&amp;gt; map = new ConcurrentHashMap&amp;lt;&amp;gt;();

    public static &amp;lt;T&amp;gt; T put(String key, T value) {
        return (T) map.put(key, value);
    }
    
    public static &amp;lt;T&amp;gt; T get(String key) {
    	return (T) map.get(key);
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then you can use it like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;UniversalMap.put("hello","world");
String who = UniversalMap.get("hello");
System.out.println(who);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 08:26:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Shared-variable-between-2-jobs/m-p/2301466#M73572</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-12T08:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: Shared variable between 2 jobs</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Shared-variable-between-2-jobs/m-p/2301467#M73573</link>
      <description>&lt;P&gt;This is my version of the sharedMap infrastructure.&lt;/P&gt; 
&lt;P&gt;1. Add a context variable &lt;FONT face="courier new,courier"&gt;sharedMap&lt;/FONT&gt; to each job&lt;/P&gt; 
&lt;P&gt;2. Create a joblet:&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sharedMap.png" style="width: 999px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M6Jx.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/155834i360947DFA3EB62A5/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M6Jx.png" alt="0683p000009M6Jx.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;3. Add this joblet to each job, and link it using an &lt;FONT face="courier new,courier"&gt;onComponentOK&lt;/FONT&gt; link at the start of the job&lt;/P&gt; 
&lt;P&gt;4. In the &lt;FONT face="courier new,courier"&gt;tRunJob&lt;/FONT&gt; components, pass the &lt;FONT face="courier new,courier"&gt;sharedMap&lt;/FONT&gt; context variable the value &lt;FONT face="courier new,courier"&gt;context.sharedMap&lt;/FONT&gt;&lt;/P&gt; 
&lt;P&gt;5. In PARENT, put the following code in a &lt;FONT face="courier new,courier"&gt;tJava&lt;/FONT&gt;:&lt;/P&gt; 
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;((java.util.map) context.sharedMap).put( "&lt;SPAN&gt;listOfThings", "" );&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt; 
&lt;P&gt;6. In SUBJOB1, put the following code:&lt;/P&gt; 
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;((java.util.map) context.sharedMap).put( "&lt;SPAN&gt;listOfThings", (String)(((java.util.map) context.sharedMap).get("listOfThings")) + my.thing );&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt; 
&lt;P&gt;...where &lt;FONT face="courier new,courier"&gt;my.thing&lt;/FONT&gt; is whatever you want to add&lt;/P&gt; 
&lt;P&gt;7. In SUBJOB2, use the following wherever you want to use the listOfThings:&lt;/P&gt; 
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;(String)(((java.util.map) context.sharedMap).get( "&lt;SPAN&gt;listOfThings" ))&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2019 15:42:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Shared-variable-between-2-jobs/m-p/2301467#M73573</guid>
      <dc:creator>PhilHibbs</dc:creator>
      <dc:date>2019-07-12T15:42:32Z</dc:date>
    </item>
  </channel>
</rss>

