Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[stellation-res] Could someone please run this program in Windows?

Could someone please run this program in Windows and report the results:
cat <Time.java
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;

public class Time{
    public static long now() {
        return new Long(new Date().getTime()).longValue();
    }
    public static long seconds(long time) {
        return time - ( time % 1000L);
    }
        
    public static long elapsed(long now, long start) {
        return now - start;
    }

    public static void main(String [] args) throws IOException {
        
        long start = seconds(now()); // Start time
        File file = new File("foo");
        for (int i = 0; i < 25; i++) {
            if (file.exists()) file.delete();
            FileWriter fileWriter = new FileWriter(file);
            fileWriter.write(new char[] {'b', 'a', 'r', '\n' });
            fileWriter.flush();
            fileWriter.close();
            long fileTime = file.lastModified();
            long now = now();
            System.out.println(" time " 
                               + elapsed(now, start) 
                               + ", file " 
                               + elapsed(fileTime, start));
            Object object = new Integer("0");
            try {
                synchronized (object) {
                    object.wait(100L);
                }
            }
            catch (InterruptedException e) {
                ; // Oh well, at least we tried to wait...
            }
        }
    }

}

Here are results for Linux (confirming File.lastModified() rounds down to nearest second):
 time 46, file 0
 time 150, file 0
 time 259, file 0
 time 370, file 0
 time 479, file 0
 time 589, file 0
 time 700, file 0
 time 810, file 0
 time 919, file 0
 time 1029, file 1000
 time 1139, file 1000
 time 1250, file 1000
 time 1359, file 1000
 time 1469, file 1000
 time 1579, file 1000
 time 1690, file 1000
 time 1799, file 1000
 time 1909, file 1000
 time 2020, file 2000
 time 2129, file 2000
 time 2240, file 2000
 time 2350, file 2000
 time 2459, file 2000
 time 2569, file 2000
 time 2680, file 2000

dave
-- 
Dave Shields, IBM Research, shields@xxxxxxxxxxxxxx. 


Back to the top