Привет, я пытаюсь запустить поток на моем «threadedSort», но я не могу использовать традиционный метод запуска void, потому что он возвращает void. Я также попытался использовать синхронизированный метод, но я не думаю, что это имело какое-либо значение ... то же самое с реентерабельным методом, я не знаю, что я делаю неправильно.Запуск потоков по файлу Метод
private static String[] getDatathread(File file) throws IOException {
ArrayList<String> data = new ArrayList<String>();
BufferedReader in = new BufferedReader(new FileReader(file));
// Read the data from the file until the end of file is reached
while (true) {
String line = in.readLine();
if (line == null) {
// the end of file was reached
break;
} else {
//synchronized(line){
lock.lock();
try{
data.add(line);
}finally{
lock.unlock();
}
//}
}
}
//Close the input stream and return the data
in.close();
return data.toArray(new String[0]);
}
}
public static String[] threadedSort(File[] files) throws IOException, InterruptedException {
String[] sortedData = new String[0];
for (File file : files) {
String[] data = getDatathread(file);
Thread.sleep(100);
data = MergeSort.mergeSort(data);
sortedData = MergeSort.merge(sortedData, data);
}
return sortedData;
}