多线程问题Thread
时间:2011-09-16
来源:互联网
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
作者: zhangzijian36 发布时间: 2011-09-16
作者: Michael_g 发布时间: 2011-09-16
作者: Rinoajun 发布时间: 2011-09-16
lz是从网上摘来的例子吧?getBigHairyMatrix()这个方法根本没有
作者: at87958208 发布时间: 2011-09-16
作者: chenliuyang 发布时间: 2011-09-16

网上抄的代码吧,没把代码抄完吧,这下悲催了吧。
作者: zhu6100441 发布时间: 2011-09-16
作者: jc8futao 发布时间: 2011-09-16
网上抄的代码吧,没把代码抄完吧,这下悲催了吧。
作者: at87958208 发布时间: 2011-09-16
按照这个字面的理解。这应该是一个锁的矩阵~!~!~!
作者: at87958208 发布时间: 2011-09-16
傻傻的告诉你 getBigHairyMatrix 是个返回 int二维数组的方法
作者: at87958208 发布时间: 2011-09-16
作者: jc8futao 发布时间: 2011-09-16
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28