Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在轮询开始前插入秒表_Java - Fatal编程技术网

Java 如何在轮询开始前插入秒表

Java 如何在轮询开始前插入秒表,java,Java,我可以知道如何从Poll()方法中为这段代码插入秒表吗?我必须计算开始计数,以便在数据库启动之前以及轮询所花费的时间 public void poll() throws Exception { st = conn.createStatement(); for (int i=0; i<10; i++) { Timestamp start; rs = st.executeQuery( "select * from msg_ne

我可以知道如何从
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());
    }


}
public void poll()引发异常{
st=conn.createStatement();

对于(int i=0;i您必须使用currentTimeMillis()函数:

启动轮询之前:

long start = System.currentTimeMillis();
轮询执行后:

long stop= System.currentTimeMillis();

执行时间是以毫秒为单位的停止-启动。

我相信
系统。currentTimeMillis
是您需要的

long startTime = System.currentTimeMillis();
// 
long endTime = System.currentTimeMillis();
System.out.println((endTime  - startTime) + "ms");
此方法比System.currentTimeMillis()更精确

引自java API:

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

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());
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");
long start = System.nanoTime();
timeThisMethod();
long end = System.nanoTime();

long howLongDidItTake = end - start;