How to instantiate objects of another class in my job?

Four Stars

How to instantiate objects of another class in my job?

Hi,

 

I have a scenario where i want to make use of udf's defined in an external class. How can i instantiate the parent class in my current job so that i can use the object instantiated across my job and sub jobs?

 

I have tried using tJava component for instantiation but the objects defined in my tjava are scoping only in very next tmap component and not beyond that.

 

How can i declare and instantiate objects at class level(can be re-used across subjobs) as defining objects in tjava has a limited scope.

 

Appreciate your suggestion, Thanks in advance.


Accepted Solutions
Community Manager

Re: How to instantiate objects of another class in my job?

An easy (but sometimes fiddly) way of doing this is to use the globalMap. Instantiate your object and add it to the globalMap. Then when you want to use it, retrieve it from the globalMap. For example....

 

Adding it to the globalMap

MyClass myClass = new MyClass();
//Do something with the object

globalMap.put("myclass", myClass); 

Then, when you want to use it....

MyClass myClass = ((MyClass)globalMap.get("myclass"));

....or you could just use it like so....

((MyClass)globalMap.get("myclass")).yourObjectMethod();

View solution in original post


All Replies
Community Manager

Re: How to instantiate objects of another class in my job?

An easy (but sometimes fiddly) way of doing this is to use the globalMap. Instantiate your object and add it to the globalMap. Then when you want to use it, retrieve it from the globalMap. For example....

 

Adding it to the globalMap

MyClass myClass = new MyClass();
//Do something with the object

globalMap.put("myclass", myClass); 

Then, when you want to use it....

MyClass myClass = ((MyClass)globalMap.get("myclass"));

....or you could just use it like so....

((MyClass)globalMap.get("myclass")).yourObjectMethod();

View solution in original post

Four Stars

Re: How to instantiate objects of another class in my job?

Hi Rhall,

 

Thank you vmuch, That works.

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 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog