2012-11-09 28 views
1

我可以告訴我如何從Poll()方法中爲這段代碼插入秒錶...我必須開始計數,以便在數據庫啓動之前以及它的時間量參加了投票。如何在投票開始之前插入秒錶

public void poll() throws Exception { 
    st = conn.createStatement(); 

    for (int i=0; i<10; i++) 
    { 
     Timestamp start; 
     rs = st.executeQuery("select * from msg_new_to_bde"); 
     Timestamp end; 
     //speed = end - start; 


     Collection<KpiMessage> pojoCol = new ArrayList<KpiMessage>(); 
     while (rs.next()) {    
      KpiMessage filedClass = convertRecordsetToPojo(rs); 
      pojoCol.add(filedClass); 

     } 
     for (KpiMessage pojoClass : pojoCol) { 
      System.out.println("=== Iteratioin Nr. " + i + "===="); 
      System.out.print(pojoClass.getSequence()); 
      System.out.print(pojoClass.getTableName()); 
      System.out.print(pojoClass.getEntryTime()); 
      System.out.print(pojoClass.getProcessingTime()); 
      System.out.println(pojoClass.getStatus()); 
      //   System.out.println(pojoClass.getprocessDuration()); 
     } 
     System.out.print(pojoCol.size()); 
    } 


} 

回答

0

你必須使用的currentTimeMillis()函數:

推出投票前:

long start = System.currentTimeMillis(); 

查詢執行後:

long stop= System.currentTimeMillis(); 

執行時間是停止 - 啓動以毫秒爲單位。

0

我相信System.currentTimeMillis是你在找什麼。

long startTime = System.currentTimeMillis(); 
// 
long endTime = System.currentTimeMillis(); 
System.out.println((endTime - startTime) + "ms"); 
0
java.util.Date date = new java.util.Date();  
Timestamp start = new Timestamp(date.getTime());  
//process  
java.util.Date date1 = new java.util.Date();  
Timestamp end = new Timestamp(date1.getTime()); 
0
long start = System.currentTimeMillis(); 
rs = st.executeQuery("select * from msg_new_to_bde"); 
long stop= System.currentTimeMillis(); 
System.out.println("execution time: " +stop-start + " ms"); 
0
long start = System.nanoTime(); 
timeThisMethod(); 
long end = System.nanoTime(); 

long howLongDidItTake = end - start; 

這種方法是更精確然後System.currentTimeMillis的()從Java API

引文:

返回最準確的電流值可用系統計時器,以納秒爲單位, 。