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() 是什么意思啊 什么作用啊
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() 是什么意思啊 什么作用啊
解决方案 »
- 回复刚才 justmewei朋友提到的简练的正则表达式的问题
- 我怎么样学习JAVA
- 求纯java代码连接sql server2000的用户登陆界面
- jtextarea 问题
- ***7000分请教:将一段C代码转换成Java代码***
- 字符串经过base64编码后的长度与原字符串的长度是什么关系呀?
- JCreator和Jbuilder一个2M,一个500多M,如果只做J2SE,用哪个好?
- 怎么使用JDK中的JDBC-ODBC桥创建数据源?????明天交作业了,急!!!!!!!
- 我想把csdn中的页子抓下来。但存不成htm页。该如何存。请指教
- 请教一个问题
- 求助!java读取word格式,比如章节名等
- 配置完环境变量后出现的不良结果,求大神解决
int[][] martrix= {
{1,2,3},{3,4,5},
{5,6,7},{7,8,9},
{9,10,11},{11,12,13},
{13,14,15},{15,16,17},
{17,18,19},{19,20,21}
};
return martrix;
}
其实就是少了个二维数组嘛~~加上就好啦~