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.

Cloud Free Trial

Try Talend Cloud free for 30 days.

Tutorial

Introduction to Talend Open Studio for Data Integration.

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.