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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:45:06+00:00 2026-06-07T06:45:06+00:00

If a queue is to be accessed by several threads, but it’s currently only

  • 0

If a queue is to be accessed by several threads, but it’s currently only being modified by a single method getNextInQueue(), what’s the most appropriate form of synchronizing access to the queue?

Currently, I declared the queue as a ConcurrentLinkedQueue, but I don’t want to reach a deadlock where multiple threads are waiting for a lock to be released. Another way I can handle this is by not synchronizing the queue, but synchronizing getNextInQueue(). However, as this code is used in the future, I don’t think this will scale as well. (Every programmer that makes modifications to the queue will have to ensure that she synchronizes the operation.)

Thoughts?

  • 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-07T06:45:08+00:00Added an answer on June 7, 2026 at 6:45 am

    I think the easiest, and most correct way is use the ConcurrentLinkedQueue. I do not believe this would cause a deadlock, however. The one thing I am not sure of, however, is how the Concurrent wrappers handle situations where you use an iterator. I seem to remember having to fall back to the old synchronized method of wrapping all calls to the underlying collection (reads and writes). I am pretty sure thats what the Concurrent wrapper is doing, though.

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

Sidebar

Related Questions

I need for a queue which can be accessed simultaneously by 2 threads, one
I have a List object being accessed by multiple threads. There is mostly one
I've got a queue (actually 3 different queues but I don't believe that will
I want to queue dependant tasks across several flows that need to be processed
I have a MySQL ISAM table being accessed my multiple php instances. Right now
I have generic Queue<T> ( System.Collections.Generic ) which is accessed for writing from one
I have an order queue that is accessed by multiple order processors through a
Can queue elements be accessed like an array? If not, then what containers similar
I would like to queue the method upload_to_scribd (from the gem scribd_fu ) using
I am trying to design a queue which could be simultaneously accessed by multiple

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.