package com.eactive.eai.adapter.socket.common; public class StopWatch { private long startTime = -1; private long stopTime = -1; public StopWatch() { } public void start() { this.startTime = System.currentTimeMillis(); } public void stop() { this.stopTime = System.currentTimeMillis(); } public void reset() { this.startTime = -1; this.stopTime = -1; } public long getTime() { if (stopTime == -1) { return (System.currentTimeMillis() - this.startTime); } else { return (this.stopTime - this.startTime); } } public String toString() { return getTimeString(); } protected String getTimeString() { int HIM = 60 * 60 * 1000; int MIM = 60 * 1000; int hours; int minutes; int seconds; int milliseconds; long time = getTime(); hours = (int) (time / HIM); time = time - (hours * HIM); minutes = (int) (time / MIM); time = time - (minutes * MIM); seconds = (int) (time / 1000); time = time - (seconds * 1000); milliseconds = (int) time; return hours + "h:" + minutes + "m:" + seconds + "s:" + milliseconds + "ms"; } static public void main(String[] strs) { StopWatch stopWatch = new StopWatch(); stopWatch.start(); try { Thread.currentThread(); Thread.sleep(1500); } catch (InterruptedException ie) { // ignore ; } stopWatch.stop(); } }