I have a process method in two of my classes which accepts a Map of String.
In the below code, I am using a for loop which will call the process method in two of my classes one by one (sequentially) which is fine.
for (ModuleRegistration.ModulesHolderEntry entry : ModuleRegistration.getInstance()) {
final Map<String, String> response = entry.getPlugin().process(outputs);
System.out.println(response);
}
But is there any way I can launch two thread for this? One thread will call process method of one of my class and second thread will call process method in my second class? And then after getting response from each thread, I want to write to the database. meaning each thread will write to database.
And also there should be timeout feature as well for each thread. We will wait for each thread a specified amount of time, meaning if one of the process method is not returned withing a certain time, then it will get timedout.
Is this possible to do in my use case? If yes, can anyone provide me an example of how to do this? Thanks.
Any help will be appreciated on this.