+ -
当前位置:首页 → 问答吧 → 多线程问题Thread

多线程问题Thread

时间:2011-09-16

来源:互联网

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() 是什么意思啊 什么作用啊

作者: at87958208   发布时间: 2011-09-16

getBigHairyMatrix() 代码找不到。

作者: zhangzijian36   发布时间: 2011-09-16

bigMatrix 是int 型二维数组指针,getBigHairyMatrix() 这个鬼才知道是做啥的。

作者: Michael_g   发布时间: 2011-09-16

lz是从网上摘来的例子吧?getBigHairyMatrix()这个方法根本没有

作者: Rinoajun   发布时间: 2011-09-16

引用 3 楼 rinoajun 的回复:
lz是从网上摘来的例子吧?getBigHairyMatrix()这个方法根本没有
是啊 从网上找的 我看的时候怎么看了一次又一次 返回去看 再百度 怎么就是没有getBigHairyMatrix().....我就愣住了。

作者: at87958208   发布时间: 2011-09-16

傻傻的告诉你 getBigHairyMatrix 是个返回 int二维数组的方法

作者: chenliuyang   发布时间: 2011-09-16


网上抄的代码吧,没把代码抄完吧,这下悲催了吧。

作者: zhu6100441   发布时间: 2011-09-16

按照这个字面的理解。这应该是一个锁的矩阵~!~!~!

作者: jc8futao   发布时间: 2011-09-16

引用 6 楼 zhu6100441 的回复:
网上抄的代码吧,没把代码抄完吧,这下悲催了吧。
不是代码没抄完...是直接把整面板复制出来啦.

作者: at87958208   发布时间: 2011-09-16

引用 7 楼 jc8futao 的回复:
按照这个字面的理解。这应该是一个锁的矩阵~!~!~!
哥们能讲讲吗?? 你讲的和书里说的有点意思。Come on.

作者: at87958208   发布时间: 2011-09-16

引用 5 楼 chenliuyang 的回复:
傻傻的告诉你 getBigHairyMatrix 是个返回 int二维数组的方法
那我也傻傻的告诉你 能不能把你懂的都说出来拉! 给你分分啦

作者: at87958208   发布时间: 2011-09-16

但是我看你的代码里面没有任何同步关键字,也无从谈起加锁的问题。

作者: jc8futao   发布时间: 2011-09-16

热门下载

更多