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

com.spun.util.timers.EventTimer Maven / Gradle / Ivy

There is a newer version: 24.9.0
Show newest version
package com.spun.util.timers;

import java.util.Date;
import java.util.HashMap;

/**
 * A Utility for timing things. this is multi-thread safe.
 **/
public class EventTimer
{
  private EventTime             time       = null;
  private HashMap startTimes = new HashMap();
  public EventTimer()
  {
    time = new EventTime();
  }
  public EventTimer(String label, long timeLimit)
  {
    time = new EventTime(label, timeLimit);
  }
  public EventTime getEventTime()
  {
    return time;
  }
  public void start()
  {
    startTimes.put("" + Thread.currentThread().hashCode(), new Date());
  }
  public void end()
  {
    Date startTime = (Date) startTimes.remove("" + Thread.currentThread().hashCode());
    if (startTime == null)
    { throw new Error("Tried to end when not started"); }
    time.add(System.currentTimeMillis() - startTime.getTime());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy