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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.