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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:48:11+00:00 2026-06-03T12:48:11+00:00

I have a LinkedBlockingQueue called tasks , but when I call tasks.take() and wait

  • 0

I have a LinkedBlockingQueue called tasks, but when I call tasks.take() and wait for a task to become available, the CPU usage is 100%. I’ve got multiple threads using the tasks.take() method (every thread has its own tasks variable). Does anybody know why this is happening?

Defenition of the tasks variable

private LinkedBlockingQueue<ComputerTask> tasks;
// snip
this.tasks = new LinkedBlockingQueue<ComputerTask>(100);

Code to take a task

ComputerTask task = tasks.take();

Code to offer a new task

this.tasks.offer(task);

P.S. I don’t know if this is a problem with my version of Java, cause I haven’t tested it on any other computers yet.

java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04-413-11M3623)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01-413, mixed mode)
  • 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-03T12:48:14+00:00Added an answer on June 3, 2026 at 12:48 pm

    I have a LinkedBlockingQueue called tasks, but when I call tasks.take() and wait for a task to become available, the CPU usage is 100%. I’ve got multiple threads using the tasks.take() method (every thread has its own tasks variable).

    tasks.take(); should not be spinning unless it is dequeuing a large number of items. If the queue is empty, it will block so I suspect this is not the cause of the 100% load. I would make sure you use a profiler or add debug statements around the take() to see if it is being called some large number of times.

    One thing to remember is that tasks.offer(task) returns false immediately if the queue is full. I’m wondering you should be using tasks.put(task) which will block instead and not spin. If you are using offer() to determine which task handler to run the task on, then maybe you are looping around and around when all of the task handlers’ queues are full?

    If you are doing your own task management, you might consider using instead one of the built-in ExecutorService classes. You then can submit all of your tasks or use a blocking queue and the ExecutorService will handle feeding each thread in the pool its tasks:

    // start 10 threads handling the tasks
    ExecutorService threadPool = Executors.newFixedThreadPool(10);
    // now submit tasks to the pools that will be run with the 10 threads
    threadPool.submit(task);
    ...
    

    In the above example ComputerTask has to implement Runnable.

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

Sidebar

Related Questions

I want to be executing some different tasks in parallel, but have the concept
I have need for a LinkedBlockingQueue but what I am passing primitives to it.
have not tested on windows. but in ubuntu when u disconnect from the network,
I have a consumer thread taking elements from a LinkedBlockingQueue , and I make
Have converted devise new session from erb to Haml but doens't work, this is
I have a LinkedBlockingQueue in a Mediator in my Producer-Mediator-Consumer model. Producer first updates
Have finally got a responsive site working (of a fashion). What I want to
Have a problem that seems easy on paper but i'm having a big problem
Have advancements in CPU design like dynamic instruction scheduling narrowed the performance gap between
I got a project where I have to make a WordCounter.. I have made

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.