Creating a globally accessible HashMap

Six Stars

Creating a globally accessible HashMap

Hi, first off I know about globalMap and context Smiley Wink
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
Community Manager

Re: Creating a globally accessible HashMap

Six Stars

Re: Creating a globally accessible HashMap

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
Six Stars

Re: Creating a globally accessible HashMap

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.
Community Manager

Re: Creating a globally accessible HashMap

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 :-)
Four Stars

Re: Creating a globally accessible HashMap

@rhall_2_0  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

Community Manager

Re: Creating a globally accessible HashMap

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)

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch