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

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

Creating a globally accessible HashMap

Hi, first off I know about globalMap and context 0683p000009MA9p.png
For various reasons I would like the option of loading up some re-usable lookup tables at the start of my job and then referencing them in code (tJavaRow etc) across subjobs. Is there a way to create variables in the scope of the TalendJob class just like globalMap? I know I could store everything in globalMap with some sensible key definition but it doesn't feel appropriate to do so and obviously I don't really want to build my own HashMap and then store /that/ in the globalMap either ...
TIA, Mark
Labels (3)
6 Replies
Anonymous
Not applicable
Author

Anonymous
Not applicable
Author

Use a routine with a ConcurrentHashMap (https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html)

OK but if I do that say, at the first block of a tJavaFlex, it will be within the scope of the enclosing subjob and I want to be able to reference it directly from components in subsequent subjobs so I'm not quite sure how that needs to be declared to have the visibility I need?
Ta, Mark
Anonymous
Not applicable
Author

OK - I have this working - create the HashMap and then store its reference in the globalMap - works well and should simplify some stuff that would otherwise require tMaps and redundant queries.
Anonymous
Not applicable
Author

You answered your own question before I saw it. That is how I deal with some of my lookups to make them a little more straight forward 🙂
Anonymous
Not applicable
Author

@rhall  can you elaborate a little and maybe give some example?

I would like to have set of variables, set their values in one job according to table (var_name, var_val) and later be able to use that variables in run if conditions and filters for outputs in many other jobs. Looks like that HashMap can be a solution for me, but I found only this article

https://help.talend.com/reader/i6eFKBuNsRD2KzBCYnXHhw/4jPcdaVw7eaDvMyLDjdYfQ , and if I understand this correctly setValue/getValue functions in tJavaRow set/get value statically only for one variable so it wont work in my case if I have 100+ variables

Anonymous
Not applicable
Author

When you say you want to use the values that have been set in RunIfs and filters in many other jobs, do you mean child jobs of the job that you are setting the values in? This is important since these will all run under the same process. They are essentially running in a single Java application. If that is the case, then this will work for you. Otherwise, you will need a different solution.

 

Assuming your requirement is for jobs running in the same process, this page goes through an example using a ConcurrentHashMap (https://www.talendbyexample.com/talend-returning-values-from-subjobs.html)