All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sitoolkit.wt.gui.infra.util.Stopwatch Maven / Gradle / Ivy

There is a newer version: 2.3
Show newest version
package org.sitoolkit.wt.gui.infra.util;

import java.text.NumberFormat;

public class Stopwatch {

    private static final NumberFormat DEFAULT_NUMBER_FORMAT = NumberFormat.getInstance();

    private static ThreadLocal threadLocalStartTime = new ThreadLocal<>();

    public static void start() {
        threadLocalStartTime.set(System.currentTimeMillis());
    }

    public static String end() {
       Long startTime = threadLocalStartTime.get();
       long currentTime = System.currentTimeMillis();

       if (startTime == null) {
           return "N/A";
       }

       return DEFAULT_NUMBER_FORMAT.format(currentTime - startTime) + "ms";
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy