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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:07:19+00:00 2026-06-17T13:07:19+00:00

I have a problem where my class is performing the first run method after

  • 0

I have a problem where my class is performing the first run method after which it is not proceeding into a second, overidden run method.

The program execution beings 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 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() {
                     MessageProcessor(outgoingQueue).generate(outgoingQueue);
                  }
               };
              new Thread(processor).start();
            }
         } catch (Exception e1) {
            e1.printStackTrace();
         }
      }
   }
}

My message processor class:

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

   public KamMsg804 MessageProcessor(Collection<KamMessage> outgoingQueue,
         Connection dbConnection) {
      this.outgoingQueue = outgoingQueue;
      this.dbConnection = dbConnection;
      return (KpiMsg804) fetchedMessages;
   }

   public Collection<KamMessage> generate(Collection<KamMessage> outgoingQueue) {
      while (true) {
         try {
            while (rs.next()) {
               KamMessage filedClass = convertRecordsetToPojo(rs);
               outgoingQueue.add(filedClass);
            }

            for (KamMessage pojoClass : outgoingQueue) {
               KamMsg804 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;
         } catch (SQLException e) {
            e.printStackTrace();
         }
      }
   }
}

My problem is exactly at the second run(9 method where I am getting exception in MessageProcessor class and it loops back to Polling.

  1. How do I implement multithreading here, as when the thread sleeps for 3 seocnds in polling it should simultaneously update the database.
  2. After which, how can the data be fed and updated back into the db.

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.

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

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

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

Problem:

Now my problem is

  1. I have to implement this update while the poll thread sleeps for 3 sec,

  2. 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.

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-17T13:07:20+00:00Added an answer on June 17, 2026 at 1:07 pm

    I can’t sugar coat this, your code is a mess. However, as far as why your message processor code is not being executed, you never actually start the thread you created with this code:

    MessageProcessor processor = new MessageProcessor() {
        // the run method which should fetch the message processor class.
        final public void run() {
             MessageProcessor(outgoingQueue).generate(outgoingQueue);                    
        }
    };
    

    Ignoring the confusingly named method being called, your code should look more like this:

    Message processor = new MessageProcessor() {
        // the run method which should fetch the message processor class.
        final public void run() {
             MessageProcessor(outgoingQueue).generate(outgoingQueue);                    
        }
    };
    
    new Thread(processor).start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem to test my non activity-class which need the context of
I have a problem with calling an overriden method from java class. I have
Good day, I have the following problem: class B extends class A and methods
I have a design problem: Question class: have a question and answer (String) TextQuestion
I have a problem with ViewHolder class. I use ViewHolder to improve my List
I have problem organizing my unittest based class test for family of tests. For
I have a problem in calling a template class I have. I declared a
i have a problem calling multiple instance of a class that i have coded
I have the problem that my view controller class has too many delegates and
I have a problem with getting a class from an external .jar file. 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.