在这里,我有线程池和另一个轮询类,用于实现轮询和从数据库中读取消息。现在的问题是我必须避免读取冗余消息以进行更新并同时处理等待的其他消息,因为有大量消息在等待。
// the code for poll method
public void poll() throws Exception {
// Method which defines polling of the data entry for counting its size.
st = conn.createStatement();
int count = 1;
long waitInMillisec = 1 * 60 * 125; // Wait for 7.5 seconds.
for (int i = 0; i < count; i++) {
System.out.println("Wait for " + waitInMillisec + " millisec");
Thread.sleep(waitInMillisec);
java.util.Date date = new java.util.Date();
Timestamp start = new Timestamp(date.getTime());
rs = st.executeQuery("select * from msg_new_to_bde where ACTION=804");
java.util.Date date1 = new java.util.Date();
Timestamp end = new Timestamp(date1.getTime());
System.out.print("Query count: ");
System.out.println(end.getTime() - start.getTime());
Collection<KpiMessage> pojoCol = new ArrayList<KpiMessage>();
while (rs.next()) {
KpiMessage filedClass = convertRecordsetToPojo(rs);
pojoCol.add(filedClass);
}