Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java multithread vs Shell script

If i have 3 tasks that i want to run all of them simultaneously, there are two ways i'm thinking of right now.

Since i'm running the program in linux, i could do it in shell script.

  java Task1 &
  java Task2 &
  java Task3 &

or, i could use one java program to spawn three child threads to do the tasks.

I want to know which way is more efficient. I doubt the shell way will create multiple JVM instance?

like image 985
user1727328 Avatar asked Feb 18 '26 21:02

user1727328


1 Answers

It would be more efficient to do this in Java, make your program multithreaded and use three threads. Yes, the shell way will create three JVM instances.

But the question is, why should you consider one alternative over the other? If this is only a small task anyway, I would personally simply start three instances in the shell as you did.

like image 165
Konrad Reiche Avatar answered Feb 21 '26 12:02

Konrad Reiche



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!