Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java multithreading easiest way to run multiple methods at once?

I've never had to multithread before, I understand what it is at a basic level. I'm wondering what would be the simplest and most efficent way to execute three methods at once?

e.g

public void test(){
method1();
method2();
method3();
}

Basically I want to execute 1,2 and 3 at the same time. I'm looking for any examples or resources which would be useful for doing this.

Thanks!

like image 629
Skizit Avatar asked Dec 14 '25 09:12

Skizit


1 Answers

If your three methods do not share state, you can just spin up a thread for each method.

http://java.sun.com/docs/books/tutorial/essential/concurrency/runthread.html

like image 91
Robert Harvey Avatar answered Dec 17 '25 00:12

Robert Harvey



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!