-6

I want to maintain thread pool, and it should contain multiple jobs. Job has execute one after another

learn java
  • 51
  • 1
  • 5
  • You're more likely to get an answer if you can show your own attempt to figure this out instead of simply asking for a solution. – Vivin Paliath May 19 '15 at 23:54
  • Please practice using Google and learn to search this forum as there's much wealth to be gained in both locations. Also in the future, you'll likely get much better and specific answers if you show the fruits of your efforts in your question and ask much more specific and answerable questions. – Hovercraft Full Of Eels May 19 '15 at 23:55
  • 1
    The "duplicate" question does not really address how to pass results of the preveious calculation to the next one. Vote to re-open. – Thilo May 19 '15 at 23:56
  • 1
    @Thilo: you're right, sorry for the close vote. It almost seems that threading is not the way to go if a job needs the results from the completion of the previous one before initiating. – Hovercraft Full Of Eels May 19 '15 at 23:58
  • 1
    Maybe you are looking for a [`Future`](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Future.html) but if your computation is inherently sequential, it will buy you nothing but additional overhead. – 5gon12eder May 20 '15 at 00:01
  • If you hover your mouse over the threadpool tag that you linked, you can see that there are over 2,300 threadpool questions, I would check those out, and hit up google. I know a guy called Jenkov talks about threadpools. He writes rather nice tutorials on Java concepts, not actually explaining code all the time, but his threadpool article does include a code example and explains it. – Ungeheuer May 20 '15 at 00:03

1 Answers1

1

If you have a sequential execution of four jobs, you probably want to aggregate them into a single Runnable.

 void run(){
      job4(job3(job2(job1(inputs))));
 }

It does not make much sense to schedule separate threads for the jobs (as only one of them can proceed at the same time).

You could submit that whole thing as one to an ExecutorService.

Thilo
  • 257,207
  • 101
  • 511
  • 656