도움을 주셔서 감사합니다. 일부 데이터베이스 작업을 수행하는 자바 기반 도구를 개발하고 있습니다. 나는 아주 간단한 문제가있다. 어떤 이유로 작업을 완료하는 데 걸린 시간이 잘못되었습니다.Java System.Time과의 혼동
public static void makeDatabaseThreaded() throws IOException, InterruptedException {
final long startTime = System.nanoTime();
ArrayList<String> tablesMade = new ArrayList<>();
File rootDirectory = root;
String[] files = rootDirectory.list();
double percentDone = 0;
double numOfTablesMade = 0;
double numberOfTables = 62.0;
DatabaseBuilderThread lastThread = null;
for (int i = 0; i <= files.length - 1; i++) {
if (!files[i].contains(".csv")) {
continue;
}
File file = new File(rootDirectory + File.separator + files[i]);
String tableName = getTableNameFromFile(file);
if (!tablesMade.contains(tableName)) {
tablesMade.add(tableName);
DatabaseBuilderThread thread = new DatabaseBuilderThread(i, file);
lastThread = thread;
thread.start();
threadsRunning++;
numOfTablesMade++;
percentDone = (int) (100.0 * (numOfTablesMade)/(numberOfTables));
while (threadsRunning > 10) {
Thread.sleep(1000);
}
System.out.println(percentDone + "% done. Making Table For File: " + file.getName());
}
}
//Make Sure all threads are done
lastThread.join();
final long endTime = System.nanoTime();
final long duration = endTime - startTime;
Time time = new Time(duration);
System.out.println("Done Making The Database. It took " + time.toString());
}
이 프로그램은 내가 실행 한 경우에 대해 실제로 두 배 정도 효과가 있다고보고합니다.
덕분에
감사합니다. 그거였다. 왠지 나는 그것이 멀티 스레딩을 일으키는 지 알아보기 위해 멀티 스레딩을 조사하고있었습니다. – Orlan