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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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.

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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

2 Replies
Anonymous
Not applicable
Author

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();
Anonymous
Not applicable
Author

Hi Rhall,

 

Thank you vmuch, That works.