我正在處理一個巨大的數據文件,並將其作爲「在下面張貼」,並在單獨的線程中讀取它。而在主線程中,我想檢索一些數據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