我正在处理一个巨大的数据文件,并将其作为“在下面张贴”,并在单独的线程中读取它。而在主线程中,我想检索一些数据frm文件,如logFile.getFileHash.getTimeStamp
,以在该timeStamp上执行一些操作。我面临的问题是,只有当我的文件在其他线程中完全读取时,如何开始从主线程的文件中读取一些数据?如何从正在工作线程上读取的文件读取主线程上的数据
注意:我不想对读取文件的同一线程上的文件检索到的数据执行操作,我想在主线程上执行此操作。
例如
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.
}
文件
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());
}
只有在读取文件后工作线程结束时,这才起作用。如果它应该做一些其他的工作,那么它不是最好的匹配。 – ciamej 2014-12-03 11:09:39