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

  • Home
  • SEARCH
  • 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 8475575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:55:50+00:00 2026-06-10T17:55:50+00:00

I have a for cylce that calls threads: if(toModify[j]==1) { getUpdate(methods_list[j],username, password); } getUpdate

  • 0

I have a for cylce that calls threads:

if(toModify[j]==1)
{
    getUpdate(methods_list[j],username, password);
}

getUpdate is a method which contains something like this:

new Thread(new Runnable() {
  public void run() {
      // *** some operations***
  }
}).start();

Through for cycle I can run each Thread simultaneously.
But if I want that each Thread starts only after the previous has stopped, can I use the following trick?

if(toModify[j]==1)
{
  int returnValue =  getUpdate(methods_list[j],username, password);
}

and add at the end of getUpdate method this code line (outside of run method):

return 1;

Using the above code each thread can start only if the previus has stopped? Or I’m wrong?

  • 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-10T17:55:52+00:00Added an answer on June 10, 2026 at 5:55 pm

    You can use RetrantLock

    private final ReentrantLock lock = new ReentrantLock();
    
    if(toModify[j]==1)        
      {   
          lock.lock();  // block until condition holds
     try {
       getUpdate(methods_list[j],username, password);         
     } finally {
       lock.unlock()
     }
    
    } 
    

    Also you will need to call join() on thread that is started from getUpdate() method.

    Thread thread = new Thread(new Runnable() { 
            public void run() { 
            // *** some operations*** 
            } 
            }); 
        thread.start();
        thread.join();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my wxPython app I have an EVT_IDLE handler that calls some function that
Consider I have 2 controls, C and CompositeC which contains C . Both C
We have a website load balanced across two servers that calls into a WCF
I have a list that calls simple_list_item_1, now I want to customise this cell,
I have an ICEfaces web app which contains a component with a property linked
I have a division operation inside a cycle that repeats many times. It so
I have three images that I want to cycle through when clicking on a
I have several environments that my SSIS packages move through during a development cycle
Being a Java developer in an agile development cycle, I have learnt that it
I have a pager for jQuery cycle, which I want to rotate on 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.