Is it possible to use threads in bash scripts. I have a driver class in java that i’m trying to run multiple instances of at the same time. The only way i know to do this is make threads in bash, but i’m not sure if thats even possible. Any help would be appreciated
Share
Bash doesn’t support threading per se, but you could launch multiple java processes in the background, like:
Anything more than that you might look into Python or Ruby, which have thread management utilities, you could wait for each one to finish and collect output/exit status, etc.
Edit: Borrowing the suggestion from @CédricJulien to use
wait, here’s a more thorough example. Given thisMyProg.javaprogram:you could write the following
bash-threads.shscript to launch multiple instances of it in parallel:Its output is: