I want to create a Java code which makes benchmark about importing xml file into SQL table. I tried this:
import java.io.IOException;
import java.nio.file.*;
import java.util.HashMap;
import java.util.List;
public class Application extends SqlUtils {
private static String folderPath = "D:\\EntityImportEversana";
public static void main(final String[] args) throws IOException, InterruptedException {
System.out.println("Running file verifier");
System.out.println("monitoring folder " folderPath);
SqlUtils sql = new SqlUtils();
WatchService watchService = FileSystems.getDefault().newWatchService();
Path path = Paths.get(folderPath);
path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY);
WatchKey key;
while ((key = watchService.take()) != null) {
for (WatchEvent<?> event : key.pollEvents()) {
System.out.println("Event kind:" event.kind() ". File affected: " event.context() ".");
if(event.kind().equals(StandardWatchEventKinds.ENTRY_DELETE)){
// Here we make a constant pull and we get the status using sql from db.
// make here start of benchmark
HashMap<String, List> map = sql.checkFileImport();
// end here of benchmark
}
}
key.reset();
}
watchService.close();
}
}
Do you know how I can make a benchmark into the above code and trace when the file is updated into db?
CodePudding user response:
You can measure the time like this:
Instant start = Instant.now();
... // do your import here
Instant end = Instant.now();
System.out.println(Duration.between(start,end));