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 9183801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:53:35+00:00 2026-06-17T18:53:35+00:00

I am trying to do multi-threading here, now I have to update my database

  • 0

I am trying to do multi-threading here, now I have to update my database using DbHandler class

The program execution begins in a controller class which has a main method and a thread pool:

public class RunnableController {
// Main method
public static void main(String[] args) throws InterruptedException {
    try {
        RunnableController controller = new RunnableController();
        controller.initializeDb();
        controller.initialiseThreads();
        System.out.println("Polling");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

   private void initialUpdate()
{
    DBhandler dbhandler = new DBhandler();
    dbhandler.updateDb(getOutgoingQueue());
}

private void initialiseThreads() {      
    try {
        threadExecutorRead = Executors.newFixedThreadPool(10);
        PollingSynchronizer read = new PollingSynchronizer(incomingQueue, dbConncetion);
        threadExecutorRead.submit(read);
    } catch (Exception e){
        e.printStackTrace();
    }   
 }
}

My poller class which fetches new data and should do updating simulateously:

 public class PollingSynchronizer implements Runnable {
     public PollingSynchronizer(Collection<KamMessage> incomingQueue,
     Connection dbConnection) {
     super();
    this.incomingQueue = incomingQueue;
    this.dbConnection = dbConnection;
 }

  private int seqId;

   public int getSeqId() {
    return seqId;
  }

   public void setSeqId(int seqId) {
   this.seqId = seqId;
 }

  // The method which runs Polling action and record the time at which it is done
    public void run() {
     int seqId = 0;

      while (true) {
        List<KamMessage> list = null;

        try {
           list = fullPoll(seqId);

           if (!list.isEmpty()) {
             seqId = list.get(0).getSequence();
             incomingQueue.addAll(list);
             this.outgoingQueue = incomingQueue;
             System.out.println("waiting 3 seconds");
             System.out.println("new incoming message");
             Thread.sleep(3000);//at this wait I should execute run()

             //when I debug my execution stops here and throws " Class not found Exception "
             // its does not enters the message processor class 
             MessageProcessor processor = new MessageProcessor() {
              //the run method which should fetch the message processor class.
              final public void run() {
               RunnableController.setOutgoingQueue(generate(outgoingQueue));
              }
           };
          new Thread(processor).start();
        }
     } catch (Exception e1) {
        e1.printStackTrace();
     }
  }
 }
}

My message processor class:

 public class MessageProcessor implements Runnable {
private Collection<KpiMessage> fetchedMessages;
private Connection dbConnection;
Statement st = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
private Collection<KamMessage> outgoingQueue;

public Collection<KamMessage> MessageProcessor(Collection<KamMessage> outgoingQueue){
    this.outgoingQueue = outgoingQueue;
    this.dbConnection = dbConnection;
    return outgoingQueue;
}
/**
 * Method for updating new values into database in preference for dummy processing of message
 * @param outgoingQueue 
 * @return 
 */
@SuppressWarnings("javadoc")
public Collection<KamMessage> generate(Collection<KamMessage> outgoingQueue)
{
        for (KamMessage pojoClass : outgoingQueue) {
            KamMessage updatedValue = createKamMsg804(pojoClass);
            System.out.print(" " + pojoClass.getSequence());
            System.out.print(" " + pojoClass.getTableName());
            System.out.print(" " + pojoClass.getAction());
            System.out.print(" " + updatedValue.getKeyInfo1());
            System.out.print(" " + updatedValue.getKeyInfo2());
            System.out.println(" " + pojoClass.getEntryTime());
        }
        return outgoingQueue;
}

/**
 * 
 * @param pojoClass 
 * @return msg
 */
public KamMessage createKamMsg804(KamMessage pojoClass)
{
    if(pojoClass.getAction() == 804){
    pojoClass.setKeyInfo1("ENTITYKEY9");
    pojoClass.setKeyInfo2("STATUSKEY9");
    }
    return pojoClass;
}
private KamMessage convertRecordsetToPojo(ResultSet rs) throws SQLException {

    KamMessage msg = new KamMessage();
    int sequence = rs.getInt("SEQ");
    msg.setSequence(sequence);
    String tablename = rs.getString("TABLENAME");
    msg.setTableName(tablename);
    Timestamp entrytime = rs.getTimestamp("ENTRYTIME");
    Date entryTime = new Date(entrytime.getTime());
    msg.setEntryTime(entryTime);
    Timestamp processingtime=rs.getTimestamp("PROCESSINGTIME");
    if(processingtime!=null){
        Date processingTime = new Date(processingtime.getTime());
        msg.setProcessingTime(processingTime);   
    }
    String keyInfo1 = rs.getString("KEYINFO1");
    msg.setKeyInfo1(keyInfo1);
    String keyInfo2 = rs.getString("KEYINFO2");
    msg.setKeyInfo2(keyInfo2);
    return msg;
}


@Override
 public void run() {

    // TODO Auto-generated method stub

 }

  }

This is my DBhandler Class, which should do updating in database

         public class DBhandler {
  Connection conn = null;
Statement st = null;
ResultSet rs = null;
PreparedStatement pstmt = null;

public DBhandler(){
    super();
}

/**
 * Method to initialize the database connection
 * @return conn
 * @throws Exception 
 * 
 */
public Connection initializeDB() throws Exception {
    System.out.println("JDBC connection");
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    conn = DriverManager.getConnection("jdbc:oracle:thin:@VM-SALES-
           MB:1521:SALESDB1","bdeuser", "edb"); // Connection for Database SALES-DB1   
    return conn;
}

 //The method for updating Database

  public void updateDb(Collection<KpiMessage> updatedQueue){
    for(KpiMessage pojoClass : updatedQueue){
       //**How the query should be used so that it gets last sequence vale and Updates into   
            Database**
           String query = "UPDATE msg_new_to_bde Set KEYINFO1= ?, KEYINFO2 = ? WHERE SEQ =  and 
           action = 804";   
      }
}
/**
 * Method for Closing the connection
 * @throws Exception 
 *
 */

     public void closeDB() throws Exception { 
    st.close();
    conn.close();
   }

    }

I just need to Update the database using update query in this class(DbHAndler) by calling the updatedQueue in the controller class.

My program flow – I have three classes: 1.Controller 2.PollerSynchro 3.Msgprocessor

I have database records, which are converted into POJO form and stored in a Collection. With these POJOs my classes try to do multiprocessing and updating in a single stretch.

Controller – has the thread pool, initiates poller class with poll method – done

Poller – should poll for new incoming messages and stores it in incoming queue – done

MsgProcessor – should look for new incoming messages and pass them from outgoing queue to incoming queue – also done

DbHandler- which should update in the database.

Problem:

Now my problem is

I have to implement this update while the poll thread sleeps for 3 sec -Done

In my code for the second void run() method in the Poller class, the outgoing queue is not passed and fed to the messageprocessor class for updating. My flow of execution only just loops back to first run method and am getting Class exception-Resolved

How to Update this in the database in Dbhanler class

Please help me to solve these problems.

  • 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-17T18:53:36+00:00Added an answer on June 17, 2026 at 6:53 pm

    The exception seems to come from this line (is this MessageProcessor.java line 38?)

    return (KpiMsg804) fetchedMessages;
    

    The fetchedMessages at this point seem to be an ArrayList.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very inexperienced using multi-threading techniques, but here is what I have tried:
I'm trying to implement multi-threading as suggested here: Spawn Multiple Threads for work then
I am trying to create a multi threaded PHP application right now. I have
New to python and trying to understand multi-threading. Here's an example from python documentation
I'm trying to figure out multi-threading programming in python. Here's the simple task with
I am trying my hardest to learn Cross/Multi Threading, but I am very confused
i'm trying to get multi tenancy working in my app - using nhibernate integration
I am trying to debug a multi-threaded Android app on a 2.3.6 device using
I am trying to post a multi-part form using httplib, url is hosted on
I'm trying to update the text of a label from a seperate class on

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.