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();

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();
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 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

Agile Data lakes & Analytics

Accelerate your data lake projects with an agile approach

Watch