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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:11:29+00:00 2026-05-30T08:11:29+00:00

What is the best way to handle RejectedExecutionException while using a ThreadPoolExecutor in Java?

  • 0

What is the best way to handle RejectedExecutionException while using a ThreadPoolExecutor in Java?

I want to ensure that the task submitted should not be overlooked and should surely get executed. As of now there are no hard real time requirements to get the task done.

One of the things I thought could be done was waiting in a loop till I know that there is space in the runnable queue, and then go on and add it to the queue.

Would be glad if people can share their experiences.

Adding the possible solution I though of:

while(executor.getQueue().remainingCapacity <= 0){
// keep looping
Thread.sleep(100);
};
//if the loop exits ,indicates that we have space in the queue hence 
//go ahead and add to the queue 
executor.execute(new ThreadInstance(params));
  • 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-30T08:11:30+00:00Added an answer on May 30, 2026 at 8:11 am

    I would change the behaviour of your queue. e.g.

    public class MyBlockingQueue<E> extends ArrayBlockingQueue<E> {
        private final long timeoutMS;
    
        public MyBlockingQueue(int capacity, long timeoutMS) {
            super(capacity);
            this.timeoutMS = timeoutMS;
        }
    
        @Override
        public boolean offer(E e) {
            try {
                return super.offer(e, timeoutMS, TimeUnit.MILLISECONDS);
            } catch (InterruptedException e1) {
                Thread.currentThread().interrupt();
                return false;
            }
        }
    }
    

    This will wait for the queue to drain before giving up.

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

Sidebar

Related Questions

What is the best way to handle mixing PHP into Javascript? Should it not
What is the best way to handle a big team that has access to
What's the best way to handle exceptions that happen from within a controller's constructor?
What is the best way to handle the following database search scenario using asp.net
What's the best way to handle having two templates (or should it be one,
What's the best way to handle binding events on elements that will be refreshed
What is the best way to handle data that needs to get send to
Can someone explain the best way to handle this approach. I am using TinyMCE
What is the best way to handle synonyms (phrases) using Lucene? Especially, when I
What is the best way to handle a link that has a video within

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.