我是否知道如何从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 :(得分:0)
您必须使用currentTimeMillis()函数:
在发布投票之前:
long start = System.currentTimeMillis();
轮询执行后:
long stop= System.currentTimeMillis();
执行时间停止 - 以毫秒为单位开始。
答案 1 :(得分:0)
我相信System.currentTimeMillis
就是你要找的。 p>
long startTime = System.currentTimeMillis();
//
long endTime = System.currentTimeMillis();
System.out.println((endTime - startTime) + "ms");
答案 2 :(得分: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());
答案 3 :(得分: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");
答案 4 :(得分:0)
long start = System.nanoTime();
timeThisMethod();
long end = System.nanoTime();
long howLongDidItTake = end - start;
此方法比System.currentTimeMillis()
更精确来自java API的引用:
返回最精确的可用系统计时器的当前值, 以纳秒为单位。