我有下面的java程序来添加两个数字..但我试图通过线程进行开发..我在看一开始应该有五个不同的线程,分别命名为 T1、T2、T3、T4、T5 和所有五个线程应该同时调用 add 方法,请教我如何实现这五个线程应该同时调用 add 方法,这样可以提高性能..
有人可以告诉我如何通过执行程序框架或 contdown 闩锁来实现这一点
public class CollectionTest {
public static void main(String args[]) {
//create Scanner instance to get input from User
Scanner scanner = new Scanner(System.in);
System.err.println("Please enter first number to add : ");
int number = scanner.nextInt();
System.out.println("Enter second number to add :");
int num = scanner.nextInt();
//adding two numbers in Java by calling method
int result = add(number, num);
System.out.printf(" Addition of numbers %d and %d is %d %n", number, num, result);
}
public static int add(int number, int num){
return number + num;
}
}