1 package org.jacorb.util.tracing; 2 3 23 24 import java.util.Calendar ; 25 import java.util.Hashtable ; 26 27 public class Timer 28 { 29 private Calendar date; 30 private Hashtable tableTable; 31 32 public Timer() 33 { 34 date = Calendar.getInstance(); 35 tableTable = new Hashtable (); 36 } 37 38 public void start(int rid, Object target) 39 { 40 try 41 { 42 Integer id = new Integer ( rid ); 43 44 Hashtable table = (Hashtable )tableTable.get( target ); 45 if( table == null ) 46 { 47 table = new Hashtable (); 48 tableTable.put( target, table ); 49 } 50 table.put( id, new Long ( System.currentTimeMillis())); 51 } 52 catch( Exception e) 53 { 54 e.printStackTrace(); 55 } 56 } 57 58 62 63 public long stop(int rid, Object target) 64 { 65 long t = System.currentTimeMillis(); 66 67 Hashtable table = (Hashtable )tableTable.get( target ); 68 if( table == null ) 69 System.err.println("errorin timer: no request table for object"); 70 71 Long startTime = 72 (Long )table.remove( new Integer (rid )); 73 74 if( startTime != null ) 75 { 76 return t - startTime.longValue(); 77 } 78 else 79 return -1; 80 } 81 } 82 83 84 85 86 87 88 89 90 91 92 93 94 | Popular Tags |