I am processing a huge data file as "posted below", and I read it on a separate thread. And in the main thread i want to retrieve some data frm that file such as logFile.getFileHash.getTimeStamp
to perform some operation on that timeStamp. The problem ia m facing is that, how to start reading some data from my file in the main thread only when my file is completely read in that other thread?
note: i do not want to do my operations on the data retrieved ffrom the file on the same thread that reads the file, i want to do so on the main thread.
example
public static void main(String[] args) throws IOException {
//fileThread.start(); will take 8 seconds.
/*
*here i want to read some data from my file to perform some processing but only
*when the thread that handles reading the file finishes work.
}
file
private static void processFile(File dataFile) throws IOException {
// TODO Auto-generated method stub
MeasurementFile logfile = new MeasurementFile(dataFile);
System.out.println(logfile.getTotalLines());
System.out.println(logfile.getFileHash().get(logfile.getTotalLines()).getFullParameters().length);
System.out.println(logfile.getFileHash().get(logfile.getTotalLines()).getEngineSpeed());
}
Try using CountDownLatch to wait until the reader finishes: http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CountDownLatch.html