You can pass a Runnable to a Thread.
Something like this will work
// rest of your code ...
public static void main(String[] args) {
test t = new test();
class R1 implements Runnable {
test tt;
public R1(test t) {tt=t;}
public void run() {tt.test1();}
}
class R2 implements Runnable {
test tt;
public R2(test t) {tt=t;}
public void run() {tt.test2();}
}
class R3 implements Runnable {
test tt;
public R3(test t) {tt=t;}
public void run() {tt.test3();}
}
new Thread(new R1()).start();
new Thread(new R2()).start();
new Thread(new R3()).start();
}
There are more elegant solutions using the reflection API.
Reputation Points: 1658
Solved Threads: 331
duckman
Offline 7,719 posts
since Nov 2004