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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:21:13+00:00 2026-06-16T05:21:13+00:00

My understanding of this is that a synchronized block keeps other threads from accessing

  • 0

My understanding of this is that a synchronized block keeps other threads from accessing until such time as that block terminates; that is, they are put on hold till then via a lock held by the currently executing class (?).

So I wrap a for block which iterates over a list and then calls clear() on that list directly thereafter, in a synchronized block. as I can’t afford to have other threads adding to the list between those two sets of operations. This is in accordance with the docs, which say,

It is imperative that the user manually synchronize on the returned
collection when iterating over it…

However I can’t figure for sure whether I need to do the same when I am adding to the list. I am guessing not, since in my case the order of add operations from different threads is not important. I guess that what I’m unsure of is whether unsynchronized modify operations might have any negative impacts?

  • 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-16T05:21:14+00:00Added an answer on June 16, 2026 at 5:21 am

    You only need locking when you have multiple operations which must work together. In the case of an Iterator, you will perform any operations over the life of the loop.

    If adds can occur in any order, no additional locking is required.

    I wrap a for block which iterates over a list and then calls clear()

    From your use case, it sounds like a BlockingQueue (is thread safe without synchronized) or even an ExecutorService (which combines a thread pool with a queue) would be a better choice.

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

Sidebar

Related Questions

So I'm having a bit of trouble understanding this example that was shown in
I am asking this question here because it is my understanding that this is
When we define custom metadata for the components, it is my understanding that this
I think I have a basic understanding of this, but am hoping that someone
My understanding is that Ladner's theorem is basically this: P != NP implies that
My understanding of finalization is this: To clean up or reclaim the memory that
It seems (at least that is our understanding of the issue at this point)
I want to verify that my understanding is correct. This kind of thing is
This is admittedly a rather loose question. My current understanding of singletons is that
I'm having a hard time understanding this. Consider the following example: protected void Page_Load(object

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.