views:

81

answers:

1

Hi guys,

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!

+5  A: 

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

Robert Harvey
So I would have to make a new class?
Ulkmun
Your class can inherit from `Thread`, or your class can implement `Runnable`.
Robert Harvey
Cheers for the help!
Ulkmun