FileDocCategorySizeDatePackage
Timestamp.javaAPI DocExample929Thu Mar 11 00:02:58 GMT 2004javathreads.examples.ch14

Timestamp

public class Timestamp extends Object

Fields Summary
private long
startTime
private long
stopTime
private boolean
stopped
private TimeUnit
ts
Constructors Summary
public Timestamp()


      
	this(TimeUnit.NANOSECONDS);
    
public Timestamp(TimeUnit ts)

	this.ts = ts;
        start();
    
Methods Summary
public longelapsedTime()

	if (!stopped)
	    throw new IllegalStateException("Timestamp not stopped");
	return ts.convert(stopTime - startTime, TimeUnit.NANOSECONDS);
    
public voidstart()

        startTime = System.nanoTime();
	stopped = false;
    
public voidstop()

        stopTime = System.nanoTime();
	stopped = true;
    
public java.lang.StringtoString()

	try {
	    return elapsedTime() + " " + ts;
	} catch (IllegalStateException ise) {
	    return "Timestamp (not stopped)";
	}
    
public java.lang.Stringunits()

	return ts.toString();