Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9116967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:47:55+00:00 2026-06-17T04:47:55+00:00

Here the method reads the database which has an unique ID with the sequence

  • 0

Here the method reads the database which has an unique ID with the sequence number which keeps on increasing, since am a beginner in java,can I know how to implement this repetitive polling and check for new incoming message each time.

public void run() {
int seqId = 0;
    while(true) {
        List<KpiMessage> list = null;
        try {
            list = fullPoll(seqId);
            if (!list.isEmpty()) {
                seqId = list.get(0).getSequence();
                incomingMessages.addAll(list);
                System.out.println("waiting 3 seconds");
                System.out.println("new incoming message");
                Thread.sleep(3000);

            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }


    }
}

//Method which defines polling of the database and also count the number of Queries
public List<KpiMessage> 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<KpiMessage> pojoCol = new ArrayList<KpiMessage>();
    while (rs.next()) {
        KpiMessage filedClass = convertRecordsetToPojo(rs);
        pojoCol.add(filedClass);
    }
    for (KpiMessage 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 seqId;           
    return pojoCol;
}  

My goal is to Poll the table from the database and also check for new incoming message, which I can find from the Header field SequenceID in table which is unique and keeps on increasing for new entries. Now my problem is

1.Lets say after I poll the first time, it reads all the entries and makes the thread to sleep for 6 seconds, by the mean time how can I get the new incoming data and Poll it again ?

2.Also how to add the new data ,when it does Polling for the second time and pass the new data to another class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:47:56+00:00Added an answer on June 17, 2026 at 4:47 am

    Poller calls fullPoll every 6 secs and passes lastSeq param to it. Initially lastSeq = 0. When Poller gets result list it replaces the lastSeq with max SEQ value. fullPoll retrieves only records with SEQ > lastSeq.

    void run() throws Exception {
        int seqId = 0;
        while(true) {
              List<KpiMessage> list = fullPoll(seqId);
              if (!list.isEmpty()) {
                seqId = list.get(0).getSequene();
              }
              Thread.sleep(6000); 
        }
    }
    
    public List<KAMessage> fullPoll(int lastSeq) throws Exception {
           ...
           ResultSet rs = st.executeQuery("select * from msg_new_to_bde where ACTION =  804 and SEQ > " + lastSeq + " order by SEQ 
          DESC");     
          .. 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the method presented here: http://cslibrary.stanford.edu/110/BinaryTrees.html#java 12. countTrees() Solution (Java) /** For the key
I have the following function which reads from a firebird database. The Function works
I have a database that stores images which can be access via a primary
I have a SL application that reads some data from the database, which I
I have a variable called $position which has a value selected from a database.
I have carried the method here on almost all of the areas where I
First, I'm speaking about the default hashCode() method here and not something overridden. When
Here's the method. I want to know if I am violating any best practices
here's the method: public static int chooseStrat () { String[] strats = new String[1]
Here's the method: public static String CPUcolor () { System.out.println (What color am I?)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.