How to synchronize update CSV file time with StopWatch object ?
<p>I implemented a Runnable which updates the CSV file every 120ms after clicking start button the problem is that in the file I have such times:</p>

<p>Data in the CSV file:</p>

<pre><code>stoper
00:00:00.144
00:00:00.286
00:00:00.421
00:00:00.551
00:00:00.679
00:00:00.811
00:00:00.937
00:00:01.064
00:00:01.192
</code></pre>

<p>Runable:</p>

<pre><code>private Runnable UpdateView = new Runnable() {
    public void run() {

            dataObject = new DataObject(stoper.toString());
            try {
                 writer.insertLine(dataObject);
             } catch (IOException e) {
                e.printStackTrace();
            }
        }
        handler.postDelayed(UpdateView, 120);
    }
};
</code></pre>

<p>Stoper class:</p>

<pre><code>public class StopWatch {
    private long startTime = -1;
    private long stopTime = -1;
    private boolean running = false;
    static public int AN_HOUR = 60 * 60 * 1000;
    static public int A_MINUTE = 60 * 1000;

    public void start() {
        if(!this.running){
        this.startTime = System.currentTimeMillis();
        }
        this.running = true;
    }


    public void stop() {
        if(this.running) {
        this.stopTime = System.currentTimeMillis();
        }
        this.running = false;

    }


    //elaspsed time in milliseconds
    public long getElapsedTime() {
        long elapsed;
        if (running) {
            elapsed = (System.currentTimeMillis() - this.startTime);
        }
        else {
            elapsed = (this.stopTime - this.startTime);
        }
        return elapsed;
    }

    public String toString() {
        return getTimeString();
    }

    /**
     * Get the time gap as a String.
     * In hours, minutes, seconds and milliseconds.
     */
    public String getTimeString() {
        int hours, minutes, seconds, milliseconds;
        long time = getElapsedTime();

        hours = (int)(time / AN_HOUR);
        time = time - (hours * AN_HOUR);
        minutes = (int) (time / A_MINUTE);
        time = time - (minutes * A_MINUTE);
        seconds = (int) (time / 1000);
        time = time - (seconds * 1000);
        milliseconds = (int) time;

        return  new DecimalFormat("00").format(hours) + ":"
              + new DecimalFormat("00").format(minutes) + ":"
              + new DecimalFormat("00").format(seconds) + "."
              + new DecimalFormat("000").format(milliseconds);
    }

}
</code></pre>

<p>I know that the problem with synchronization stoper.toString() with the update but I don't know how to do it that my file look like this:</p>

<pre><code>stoper
00:00:00.120
00:00:00.240
00:00:00.360
00:00:00.480
00:00:00.600
     .
     .
     .
</code></pre>

<p>Please help !!!</p>
