I have an application which has to process XML files by adding metadata from a remote database. Since I’m opening and parsing them in Java, I thought threading might improve the performance (by processing the document while my application waits for the response from DB).
Let’s say I have two methods:
HashMap result = getMetadata(String id);
Document doc = loadDocument(String path);
I would like to start both simultaneously and wait for both to finish. Can I do this inline?
Regards,
Michael
You can start two Threads and use
join()to wait for them to finish.If you want to get the results of two tasks, you can use an ExecutorService and give it a Callable. Later, you can
future.get()the results in the current thread when they are finished.