The problem is like this. I need to process a large file multiple times. So I think threads will help me increase the time. So far I have done this
The class that implements Runnable
:
public class ProcessFile() implements Runnable {
private int max;
private int i;
private int j;
public ProcessFile(int i, int j) {
this.i = i;
this.j = j;
}
public void run() {
//Perform operations on the file
}
public int getMaximum() {
return this.max;
}
}
and the class from which I call the thread:
public calss Start {
public static void main(String[] args) {
for (int i=0;i<=10;i++) {
for (int j=0;j<=5;j++) {
ProcessFile pf = new ProcessFile(i,j);
new Thread(pf).start();
int maximum = pf.getMaximum();
if (max > currentNr)
System.out.println("max is = " + max);
}
}
}
}
In the code above I intended to compute the maximum each time from the text file, and then return it back in the main program and then process this value. The code above doesn't seem to work since no value is displayed.
EDIT. Since I create the threads in the second loop I want to create 5 threads. Each of them performs the same operations on the file but under different criteria. Also each of this threads should return a value, that should be processed one at a time in the method that created the threads.