How to Multiple Instances of Java Objects of globally for other services in different packages to use?

57 Views Asked by At

Example, there is a Task.java object, and I have multiple instances of this object, and I need to store all those for other services to access globally. One possible way I acknowledge is to create a new class of those objects, suppose, Tasks.java

Tasks.java {
Task TaskA,
Task TaskB,
Task TaskC
}

And store this Tasks instance in Global Context. Is there a way we can store multiple instances of the same object in global contexts without creating a new class? One more way might be by using dependency injection in Java which I want to avoid. Or any other different better way to do this?

I have tried: Contexts.globalContext().register(task);

where task is an instance of Task.java class. I want to store multiple instances of Task in this global Context.

1

There are 1 best solutions below