我有下面的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;
}
}
你想看看當多個線程砰的一發生什麼事單一方法?? –