This is the first time I am writing multiple threaded program. I have a doubt that multiple thread which I'l create will point to the same run method and perform the task written in run(). but I want different threads to perform different tasks e.g 1 thread will insert into database other update and etc. My question is how to create different threads that will perform different tasks
Create your threads that do different jobs:
public class Job1Thread extends Thread {
@Override
public void run() {
// Do job 1 here
}
}
public class Job2Thread extends Thread {
@Override
public void run() {
// Do job 2 here
}
}
Start your threads and they will work for you:
Job1Thread job1 = new Job1Thread();
Job2Thread job2 = new Job2Thread();
job1.start();
job2.start();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With