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());
    }


}
4

5 回答 5

0
long start = System.nanoTime();
timeThisMethod();
long end = System.nanoTime();

long howLongDidItTake = end - start;

这种方法比 System.currentTimeMillis() 更精确

来自 java API 的引用:

返回最精确的可用系统计时器的当前值,以纳秒为单位。

于 2012-11-09T11:14:52.550 回答
0

您必须使用 currentTimeMillis() 函数:

启动轮询之前:

long start = System.currentTimeMillis();

轮询执行后:

long stop= System.currentTimeMillis();

执行时间是停止 - 以毫秒为单位开始。

于 2012-11-09T10:39:01.980 回答
0

我相信System.currentTimeMillis这就是你要找的。

long startTime = System.currentTimeMillis();
// 
long endTime = System.currentTimeMillis();
System.out.println((endTime  - startTime) + "ms");
于 2012-11-09T10:39:19.067 回答
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());
于 2012-11-09T10:41:37.350 回答
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");
于 2012-11-09T10:45:27.997 回答