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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:01:41+00:00 2026-05-15T16:01:41+00:00

I have a pool of threads which are working independently. Basically these threads are

  • 0

I have a pool of threads which are working independently. Basically these threads are getting data from websites. I have also another thread which change my System IP. I just need to pause all other threads while another thread is changing ip. As soon as ip will change then other threads pool will resume.

Is there any solution?

Here is my Code:

for(;;){
  for (int aa = 0; aa < pages.size(); aa++) {
    if (pageID != null) {
      t = new Thread(new BackgroundThread(pageID.get(aa)));
      System.out.println(pageID.get(aa));
      t.start();
    }
    if(ipNo == 3){
      ipNo = 0;
    }
    if(aa == 35) {
      //Following method take a little bit time to change ip. I need when this method will be executin then 
      //all above threads "t" will be paused
      IPRotator.rotateIP(ip[ipNo]); 
      //When IP will be change then all paused threads will be resumed
      ipNo++;
    }
  }
}
  • 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-05-15T16:01:42+00:00Added an answer on May 15, 2026 at 4:01 pm

    I’m assuming you really mean you are changing the machine IP? You need to be sure that the threads are in a state where the system IP can be changed, and also that the system IP changer needs to wait until all threads are pausing for the IP to be changed.

    This can be done using a CountDownLatch to indicate that threads should pause – each thread counts down the latch. When all threads have hit the latch, the system IP updater can proceed. Once it’s done it’s work, it then resumes the threads by setting the latch to null.

    Exception handling omitted for clarity.

      class SystemIPChanger implements Runnable {
          Collection<WorkerThread> pool;
    
          public void changeIP() {
              pauseAllThreads();
              changeIP();
              resumeThreads();
          }
    
          void pauseAllThreads() {
              CountDownLatch latch = new CountDownLatch(pool.size());
              for (WorkerThread worker : pool) {
                  worker.setPause(latch);
              }
              latch.await();          
          }
    
          void resumeThreads() {
              for (WorkerThread worker : pool) {
                  worker.setPause(null);
              }
    
          }
      }
    
      class WorkerThread implements Runnable {
        private CountDownLatch pause;
    
        public void run() {
            while (...) {
                pause();
                doRealWork(); 
            }
        }
    
    
        synchronized void pause() {
            CountdownLatch latch = pause;
            if (latch!=null) {
               latch.countDown();
               while (pause==latch) {
                   wait();
               }
            }
        }
    
        public synchronized void setPause(CountDownLatch latch) {
            this.pause = latch;
            notifyAll();
        }
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Thread::Pool::Simple for multi-threading. I have a couple of questions which are quite
I have created a thread pool in C++ which stores all tasks in a
I have a simple thread pool written in pthreads implemented using a pool of
I have a program which accepts 2 N -digit numbers, multiplies them using threads
I have 300 threads which is executing one by one. I use join, so
Does every thread have to have its own pool? I am writing an iPhone
I have a UDP based application that is implemented using a thread pool. Messages
Per this helpful article I have confirmed I have a connection pool leak in
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I'm working on a simple job threading framework which is very similar to the

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.