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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:08:37+00:00 2026-06-18T14:08:37+00:00

How to pass the polling thread to another thread for processing. The program execution

  • 0

How to pass the polling thread to another thread for processing.
The program execution beings in a controller class which has a main method and a thread pool:

The main class Controller

   public static void main(String[] args) throws InterruptedException {
    RunnableController controller = new RunnableController();

    System.out.println(incomingQueue.size());

    controller.initializeDb();
    controller.initialiseThreads();
    System.out.println("Polling");
    controller.initialUpdate(); 

}

The method which has the thread for Polling class

 private void initialiseThreads()
{       
    try {

        threadExecutorRead = Executors.newFixedThreadPool(10);
PollingSynchronizer reader = new PollingSynchronizer(incomingQueue,dbConnection);   
        threadExecutorRead.submit(reader);

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

}

The method which has the thread for the proccesor class

    private void initialUpdate()
{
    RunnableController.outgoingQueue = incomingQueue;
    if((RunnableController.outgoingQueue)!= null){
        try {
            threadExecutorFetch = Executors.newFixedThreadPool(10);
        MessageProcessor updater = new MessageProcessor(outgoingQueue, dbConnection);
            threadExecutorFetch.submit(updater);
            DBhandler dbhandler = new DBhandler();
            dbhandler.updateDb(getOutgoingQueue());

        } catch (Exception e) {

        }
    }

}

The Poller Class and the controller class

    public void run() {// Thread in the Poller class 
    int seqId = 0;
    while(true) {
        List<KpiMessage> list = null;
        try {
            list = fullPoll(seqId);
            if (!list.isEmpty()) {
                seqId = list.get(0).getSequence();
                incomingQueue.addAll(list);
                this.outgoingQueue = incomingQueue;             
                System.out.println("waiting");
                System.out.println("new incoming message");
                while(true){
                        wait(3000);
                        notify();
                }
            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }
}


          public void run() {// Second thread in the Processor Class
    synchronized (this){
        RunnableController.setOutgoingQueue(generate(outgoingQueue));
    }
    notify();
}   
 } 

My task and Question is :

1.The controller should handle both the threads Poller & processor and it should only call the poller & processor thread

2.Now My question is how to make the poller thread wait for 3 seconds and paralelly notify the processor.

I get the error as follows:

java.lang.IllegalMonitorStateException
    at java.lang.Object.wait(Native Method)
    at PollingSynchronizer.run(PollingSynchronizer.java:76)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

How to achieve asynchronous processing here?

  • 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-18T14:08:39+00:00Added an answer on June 18, 2026 at 2:08 pm

    You need to read something like this first. You cannot use wait() without holding the object’s monitor. Also, from a short glance, it looks like you use a non-final static member in a multithreading context. Try to make that thread-safe.

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

Sidebar

Related Questions

I have another thread polling user input. This thread is the main thread and
Here the method reads the database which has an unique ID with the sequence
I have a stand alone java program having 'main method' that runs continuously in
I've got a thread that's polling a piece of hardware. while not hardware_is_ready(): pass
I am trying to pass the fullcalendar events to my controller via Json, however
I am trying to pass a simple JSON object to a controller using MVC3
I have a servlet method where i need to pass a json object. This
I have a Manager (main thread), that creates other Threads to handle various operations.
I have a page which has a small form with one input field and
I have a task that would benefit from the Thread Pool design pattern (many

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.