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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:50:18+00:00 2026-06-07T02:50:18+00:00

I want to schedule the same command in a parallel fashion using executor service

  • 0

I want to schedule the same command in a parallel fashion using executor service in Java. I wrote a wrapper over thread pool executor, which takes the parallel count to schedule the command as parameter and in a for loop, schedules the command(i.e. same instance multiple times).

Is this approach correct? Is there any suggested way of doing this? I am using spring to create these beans.

  • 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-07T02:50:20+00:00Added an answer on June 7, 2026 at 2:50 am

    You could use the ScheduledExecuterService as follows:

    import java.util.concurrent.Executors;
    import java.util.concurrent.ScheduledExecutorService;
    import java.util.concurrent.TimeUnit;
    
    public class ScheduledExecutorTest {
    
        private final static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
    
        public static void main(final String[] args) throws InterruptedException {
            scheduler.scheduleAtFixedRate(new Runnable() {
                public void run() {
                    System.out.println("executed");
                }
            }, 0, 1, TimeUnit.SECONDS);
    
    
            Thread.sleep(10000);
            scheduler.shutdownNow();
        }
    
    }
    

    This will execute the run method every second starting immediately.

    With this approach you can add it multiple times to the scheduledExecuterService:

    Runnable command = new Runnable() {
        public void run() {
            System.out.println("executed");
        }
    };
    scheduler.scheduleAtFixedRate(command, 0, 1, TimeUnit.SECONDS);
    scheduler.scheduleAtFixedRate(command, 0, 1, TimeUnit.SECONDS);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using DESede encryptation in Java and I want to make the same encryptation
My plugin includes a custom content textarea and I want add the same schedule
I am using Quartz Scheduler using Spring. I want to configure the same with
I have a schedule/calendar app that I wrote in Rails that I'm rewriting using
I want to schedule events to happen for my users. Is there an efficient
I want to schedule the email with asp.net and C# code. what is basic
I want to schedule my jasper report so that at a particular time, it
I want to develop an app to display the programs schedule of a specific
I want to run a sql query on a specific schedule (weekly) and need
What I want basically to acomplish is to schedule on a task_group new work

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.