日期:2014-05-20  浏览次数:20704 次

多线程问题Thread
public class TenThreads {
private static class WorkerThread extends Thread {
int max = Integer.MIN_VALUE;
int[] ourArray;
public WorkerThread(int[] ourArray) {
this.ourArray = ourArray;
}
// Find the maximum value in our particular piece of the array
public void run() {
for (int i = 0; i < ourArray.length; i++)
max = Math.max(max, ourArray[i]);
}
public int getMax() {
return max;
}
}
public static void main(String[] args) {

//====================
WorkerThread[] threads = new WorkerThread[10];
int[][] bigMatrix = getBigHairyMatrix();
//==================问题在这里啦! 
int max = Integer.MIN_VALUE;
// Give each thread a slice of the matrix to work with
for (int i=0; i < 10; i++) {
threads[i] = new WorkerThread(bigMatrix[i]);
threads[i].start();
}
// Wait for each thread to finish
try {
for (int i=0; i < 10; i++) {
threads[i].join();
max = Math.max(max, threads[i].getMax());
}
}
catch (InterruptedException e) {
// fall through
}
System.out.println("Maximum value was " + max);
}
}
==============================================================
WorkerThread[] threads = new WorkerThread[10];
int[][] bigMatrix = getBigHairyMatrix();
我想请问一下:int[][] bigMatrix = getBigHairyMatrix();
getBigHairyMatrix() 是什么意思啊 什么作用啊

------解决方案--------------------
bigMatrix 是int 型二维数组指针,getBigHairyMatrix() 这个鬼才知道是做啥的。
------解决方案--------------------
傻傻的告诉你 getBigHairyMatrix 是个返回 int二维数组的方法
------解决方案--------------------
但是我看你的代码里面没有任何同步关键字,也无从谈起加锁的问题。