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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:36:57+00:00 2026-06-06T12:36:57+00:00

I developed a program which after every two minutes call db to check new

  • 0

I developed a program which after every two minutes call db to check new tasks

public static void main(String[] args) {
ScheduledExecutorService scheduler =     Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleWithFixedDelay(new ESMSCampaignTask(), 0, 2, TimeUnit.MINUTES);
}

Now following code check from DB and execute threads

public void run() {

    ExecutorService execService = Executors.newFixedThreadPool(5);

    List<ScheduledCampaigns> scheduledCampaignsList =   campaignsService.getScheduledCampaigns();

    for (ScheduledCampaigns campaign : scheduledCampaignsList) {

        String cmpName = "SCH_CAMPAIGNS_" + campaign.getCampaign_id();

        execService.execute(new Runnable() {
            public void run() {
                smppService.submitShortMessage(campaign);
            }
        });

    }//EO For Loop

}//EO Run

The solution i am looking for is that how i can get status of completion of above threads so that i update DB accordingly?

I tried to execService.awaitTermination(500, TimeUnit.SECONDS);

But i would not be able to start new threads until existing threads finish their task.

So solution should provide such functionality that i could be able to start new threads after every two minutes without waiting for existing threads completions and meanwhile i keep on getting status of threads completion so i update database accordingly.

Regards,

  • 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-06T12:37:00+00:00Added an answer on June 6, 2026 at 12:37 pm

    If you use ExcecutorService.submit() rather than execute, you can get a Future object.
    Store this in a vector, and you can then loop through the items in this vector to check on their completion state.;

    /**  keep track of currently running tasks */
    Vector runningTasks<Future> = new Vector<Future>();
    
    public void run(){
      for (ScheduledCampaigns campaign : scheduledCampaignsList) {
    
        String cmpName = "SCH_CAMPAIGNS_" + campaign.getCampaign_id();
    
        Future f = execService.submit(new Runnable() {
            public void run() {
                smppService.submitShortMessage(campaign);
            }
        });
        runningTasks.add(f);
    
      }//EO For Loop
    
      // which tasks have just completed?
      Vector<Future> justCompletedTasks = new Vector<Future>();
    
      // check currently executing tasks
      for (Future task : runningTasks){
       if( task.isDone() || tasks.isCancelled() ){
          justCompletedTasks.add(task);
       }
      } // EO check executing tasks
    
      // remove completed tasks from current list
      runningTasks.removeAll(justCompletedTasks);
    } // EO run
    

    Sorry this is untested, but hope the idea is useful?

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

Sidebar

Related Questions

i have recently developed a list program in android in which there is an
I have enrolled in the iOS developer's program. I've developed an app which I
I have a binary program developed for Linux which reads lines from a server's
I have developed a program which makes use of serial programming to read and
I'm new to C#, and want to develope a program with which I could
Similar to: program not executing anything after a call to system() I am fairly
I have developed a program in PHP which opens IE on a button click.
I developed a WCF Data Service, which runs fine, I can do every operation
I've developed a user-control class which i intent to use for buttons . After
I lunched a simulator program which developed on C++ in my Ubuntu 11 when

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.