-
multi thread
i have no idea about how to create multi-thread to read different files.
http://img72.imageshack.us/img72/367...1210014118.jpg
Uploaded with ImageShack.us
i just can read the .dat to find the max no.
here is my code
Code:
import java.io.*;
public class Max extends Thread
{
public Max(){
}
synchronized public void run(){
int max = Integer.MIN_VALUE;
try{
FileInputStream fis = new FileInputStream("C:/Documents and Settings/him/file2.dat");
DataInputStream dis = new DataInputStream(fis);
while(dis.readInt()!= -1){
int x = dis.readInt();
if(x > max) max = x;
}
}
catch (IOException e ){
System.out.println(e);
}
finally{
System.out.println(max);
fis.close();
}
public static void main ( String[] args ) {
Max a = new Max();
a.start();
}
}
-
Re: multi thread
Is it necessary use db?
It just a java homework.
can someone give me some hints??
:=(:
-
Re: multi thread
No it's not necessary to use a database but rather just some simple code will do.
As for helping, your posted code is not very readable. Please read the links that Darryl has given you so you can correct this problem.
-
Re: multi thread
I have fixed my code.
I just know how to find out the max no. in the .dat file by creating a instance.
I dun know how to create three different threads to read each of the file .
How can i do to match the requirement above.
-
Re: multi thread
Well for starters, you're hard coding your input in a single thread. That'll never work. Why not start with getting the list of input files working first?