Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple threads performing different tasks

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

like image 706
happy Avatar asked Dec 12 '22 01:12

happy


1 Answers

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();
like image 117
alexey28 Avatar answered Dec 23 '22 17:12

alexey28