I have class A in which i have two methods defined ValidateA and ValidateB
class A {
ValidateA() {
/////
}
ValidateB() {
////
}
}
I want to run both these steps in parallel at same time and get there combined status. How can i proceed using threads?
It is always recommended to make use of the great
Executorsclasses introduced in Java 5. They help you manage your background tasks and hides theThreadcode from your classes.Something like the following would work. It creates a thread-pool, submits 2
Runnableclasses which each call one of the validate methods, and then waits for them to finish and return. It uses aResultobject that you will have to make up. It could also be aStringorIntegerand depends on what the validate methods return.