how to make the below code as reusable in this scenario

now we are connecting third party service for each job for getting service context .lets say if 100 jobs are there, for every job it will try to connect third party to make this code as reusable so that if the service Context  already exists for these data types i.e. DAT or CMT or TMT then other jobs WHICH IS HAVING THESE DATA types should reuse the existing service Context .
public void setContext(String dataType) {


for (in i=0;i<jobs.length ;i++ )
		String dataType=jobs[i].getDataType();//this data will be either of DAT,CMT,TMT
Service query = serviceFactory.getRemoteService(Service.class,utility.getServiceContext());

Open in new window

LVL 20
chaitu chaituAsked:
Who is Participating?
CEHJConnect With a Mentor Commented:
Difficult to know without knowing how these key classes actually work but you could/should get your factory to create the correct service context for each type. When the service is requested, the factory would return the instance initialized with the correct context, only creating where contexts/services don't already exist in the factory's cache
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.