我有以下三种方法的课程
public class MyRunnable implements Runnable {
@Override
public void run() {
// what code need to write here
//to call the specific methods based on request types
}
public int add(int a, int b){
return a+b;
}
public int multiply(int a , int b){
return a*b;
}
public int division(int a , int b){
return a/b;
}
}
和我的主要班级一样
在这里r.multiply(),add()和divide()方法将按顺序执行,但是我想以多线程方式执行它们,因此我可以更快地得到结果.如何基于输入动态调用类的方法.如何传递给线程以及如何将结果从线程返回给调用线程.
public class ThreadDemo {
public static void main(String[] args) {
MyRunnable r = new MyRunnable();
// how to do below calculation using multihtreading
// how to call a method and how to get result of a thread of same class
int result =