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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:16:44+00:00 2026-06-09T00:16:44+00:00

I have a single thread pool ExecutorService object. At some time in the future

  • 0

I have a single thread pool ExecutorService object. At some time in the future tasks are added to be done using the submit() method. My understanding is that submit will submit add the submitted Runnable to the end of the list of tasks to be done. However I have a situation where based on a boolean I may want to submit the runnable to the front of the tasks to be executed. I don’t want this to affect the current task, just that the next task done will be the one I just gave it. An example method is reproduced below. How do I do this?

Thanks

private ExecutorService singleLoadPool = Executors.newSingleThreadExecutor();
public void submitTask(Runnable run, boolean doNow) {
    if (doNow)
        singleLoadPool.submitFront(run);  // This is the method I'm looking for
    else
        singleLoadPool.submit(run);
}
  • 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-09T00:16:46+00:00Added an answer on June 9, 2026 at 12:16 am

    My preference would be use a LinkedBlockingDeque. It directly supports positional inserts/removes – putFirst(e)/takeFirst() and putLast(e)/takeLast() – which is your primary requirement- you dont have to implement a Comparator for your elements. Also this is bounded – which means that it provides safety against OutOfMemoryError.

    edit In response to latest question :

    First , have the ExecutorService like

    ExecutorService executorService = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, workQueue);

    Second , the important question is : what is the workQueue ?

    The workQueue is a thin wrapper over any BlockingQueue implementation , which delegates all its methods to a LinkedBlockingDeque instance that it contains, except for the offer() method , which is called on it by the ThreadPoolExecutor and which needs to be overriden, like this :

           public boolean offer(E e) {
           if(doNow)
             return linkedBlockingDequeInstance.offerFirst(e);
          else 
             return linkedBlockingDequeInstance.offerLast(e);
       }
    

    Ofcourse when you override any method – you need to careful to preserve thread safety and its general contract.Definitely this requires careful thought and rigorous testing.

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

Sidebar

Related Questions

I have a single thread producer which creates some task objects which are then
I have a single xml file and every new thread of the program (BHO)
Does anybody have an idea why Google App Engine permits only a single thread
In WebForms ASP.NET site (IIS, single app pool), I have call to lengthy web
I have been reading about the thread-pool pattern and I can't seem to find
i have a single filed which i need to clone with a clone button
I have A single page that has the following structure <form runat=server><placeholder></placeholder></form> I have
i have a single video (duration: 3 seconds) and i need to create 2
I have a single-view application that takes in a username and a password and
I have a single page website that changes content based on variables passed through

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.