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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:34:06+00:00 2026-05-31T05:34:06+00:00

So I have a SomeTask class which extends Thread , and it has Map

  • 0

So I have a SomeTask class which extends Thread, and it has Map and List fields. What would be the behavior when you don’t do Collections.synchronizedXXX and you have multiple thread of SomeTask running?

Once a Map is called from the database (I am using Object Database to directly store POJO), would I need to synchronized the Map object returned from this database as well?

Map SomeTasksOwnMap = Collections.synchronizedMap(MapReturnedFromDatabase);

  • 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-31T05:34:06+00:00Added an answer on May 31, 2026 at 5:34 am

    Collections.synchronizedXXX is required when 2 or more Threads are accessing the same Map/List.

    If your task doesn’t access other tasks Map/List, then there is no need to synchronize them.

    Example.

    • Task 1 builds a list of numbers divisible exactly by 2.
    • Task 2 builds a list of numbers divisible exactly by 3.

    These two tasks have individual lists that do not require synchronization.

    Example require synchronization.

    • Task 1 and 2 both calculate numbers and store them in a shared list.

    To answer the questions: “What would be the behavior when you don’t”, you could lose one of the writes if it was timed that both threads wanted to write to index ‘x’.

    You may also have a null value in the list as the size of the array was increased before the write to the location was done.

    Basically you would have an inconsistent view.

    • 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 daemon thread which wakes up at a specified interval to do
I have the following code in Main.java : public class Main extends Activity implements
Say for an example:- I have created thread pThread using CreateThread Api which will
see i have one library which has two api lets call api1() and api2()
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Would be a nice thing - do I have to write a script or
I have a progress which I mintor with a QProgessDialog in PyQt4. Basicly, I
I have an legacy in house business application which is running in one JVM
i have html code block like this <div id=some-div> <a href=# class=link-click>some link text</a>

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.