Thread class has run method to implement the business logic that could be executed in parallel.But I want implement different business logics in a single run method and to run simultaneously.How to get this feature.
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think that the best course of action would be to have two separate threads.
You can (and probably should) write a new class that implements
Runnableand inside it place your logic.If there are common activities between the two business logics that you have to implement, you can use this class as a base class for the two “Runnables”.
Each
Runnableshould be spawned in a separate thread.You can find very good reasoning for
Thread vs. Runnableon this post:"implements Runnable" vs. "extends Thread"