From 414910fbe8e5e63e298ff72fd74ebc37b3da7a7f Mon Sep 17 00:00:00 2001 From: victor Date: Tue, 9 Oct 2007 14:11:45 +0200 Subject: [PATCH] Added LogThread.java; a thread that will log timestamps. --- LogThread.java | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 LogThread.java diff --git a/LogThread.java b/LogThread.java new file mode 100644 index 0000000..9712db9 --- /dev/null +++ b/LogThread.java @@ -0,0 +1,36 @@ +import java.util.*; +import java.io.*; + +public class LogThread extends Thread { + + public LogThread() { + } + + public void writeToFile(String filename) { + long startNano = System.nanoTime(); + try { + this.sleep(500); + } + catch (InterruptedException e) { + System.out.println(e); + } + try { + FileWriter file = new FileWriter(filename); + BufferedWriter out = new BufferedWriter(file); + for (int i=0; i<10; i++) { + out.write("Average time for a packet to circle the ring: " + + (double)(System.nanoTime() - startNano)/12 + " ms\n"); + } + out.close(); + } + catch (IOException e) { + System.out.println(e); + } + } + + public static void main(String args[]) { + LogThread trad = new LogThread(); + trad.writeToFile("a-log.txt"); + } + +} \ No newline at end of file -- 2.11.4.GIT