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

  • Home
  • SEARCH
  • 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 4052014
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:16:01+00:00 2026-05-20T14:16:01+00:00

In a multi-thread module, I don’t care whether it is thread-safely writing over a

  • 0

In a multi-thread module, I don’t care whether it is thread-safely writing over a java.util.Collection (e.g. java.util.Set) object. What it does is removing some independent elements by multiple threads, which may perform removal on the same element at the same time. Then, what happens? That element is removed, or any exception is thrown?


Kejia

  • 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-20T14:16:02+00:00Added an answer on May 20, 2026 at 2:16 pm

    It is even possible that an ConcurrentModificationException is thrown, when you remove different objects. That depends on the implementation of the Set you are using: The remove() method may iterate over the set. Or worse: It may modifies some other internal variables and leave the set in an inconsistent state without throwing any exception.

    There is a really easy solution:

    Set safeSet = Collections.synchronizedSet(set);
    

    You still need to pay attention if you want to iterate over it, as described in the apidoc: http://download.oracle.com/javase/6/docs/api/java/util/Collections.html#synchronizedSet%28java.util.Set%29 but all the other methods (including remove) are fine.

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

Sidebar

Related Questions

I am writing multi-thread socket chat in C++Builder 2009. It is almost complete in
I have a layered application in Java which has a multi thread data access
I am coming up with a design for a task based multi-thread java 1.5
How should implement multi-thread in single-threaded Operating system using java? Java supports Multi-threading.Is there
I am running Sql Server Compact Edition 3.5.1.0 SP1 in a multi-thread application. The
I have perl, v5.6.1 built for MSWin32-x86-multi-thread Binary build 638 provided by ActiveState. I
I've written a simple multi-threaded game server in python that creates a new thread
i'm working with a multi-threaded program (using pthreads) that currently create a background thread
How do I multi-thread so that it will run private or public functions in
I was trying to download images with multi-thread, which has a limited max_count in

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.