1

此类进行轮询并检查新的传入消息。现在我怎样才能同时实现轮询和检查新数据?最后所有的数据都必须反馈给 Polling

public void run() {
int seqId = 0;
    while(true) {
        List<KamMessage> list = null;
        try {
            list = fullPoll(seqId);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        if (!list.isEmpty()) {
            seqId = list.get(0).getSequence();
            incomingMessages.addAll(list);
            System.out.println("waiting 3 seconds");
            System.out.println("new incoming message");
        }
        try {
            Thread.sleep(3000);
            System.out.println("new incoming message");
        } catch (InterruptedException e) {
            e.printStackTrace();
        } 
    }
}
public List<KamMessage> fullPoll(int lastSeq) throws Exception {
Statement st = dbConnection.createStatement();
ResultSet rs = st.executeQuery("select * from msg_new_to_bde where ACTION =  804 and SEQ >" +
lastSeq + "order by SEQ DESC");      
    List<KamMessage> pojoCol = new ArrayList<KamMessage>();
    while (rs.next()) {
        KamMessage filedClass = convertRecordsetToPojo(rs);
        pojoCol.add(filedClass);
    }
    for (KamMessage pojoClass : pojoCol) {
        System.out.print(" " + pojoClass.getSequence());
        System.out.print(" " + pojoClass.getTableName());
        System.out.print(" " + pojoClass.getAction());
        System.out.print(" " + pojoClass.getKeyInfo1());
        System.out.print(" " + pojoClass.getKeyInfo2());
        System.out.println(" " + pojoClass.getEntryTime());
    }           
    return pojoCol;
} 

我的任务是从数据库中轮询表并检查新的传入消息。首先轮询后我得到新的传入数据,现在我的问题是

1.如何将此新数据传递给另一个类,以处理消息。

2.以及如何将其反馈回数据库并再次调用轮询。

3.如何并行实现

4

0 回答 0