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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:47:04+00:00 2026-05-10T17:47:04+00:00

I fill a collection one single time when my J2EE webapp starts. Then, several

  • 0

I fill a collection one single time when my J2EE webapp starts. Then, several thread may access it at same time but only to read it.

I know using a synchronized collection is mandatory for parallels write but do I still need it for parallels read ?

  • 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. 2026-05-10T17:47:05+00:00Added an answer on May 10, 2026 at 5:47 pm

    Normally no because you are not changing the internal state of the collection in this case. When you iterate over the collection a new instance of the iterator is created and the state of the iteration is per iterator instance.


    Aside note: Remember that by keeping a read-only collection you are only preventing modifications to the collection itself. Each collection element is still changeable.

    class Test {     public Test(final int a, final int b) {         this.a = a;         this.b = b;     }      public int a;     public int b; }  public class Main {      public static void main(String[] args) throws Exception {         List<Test> values = new ArrayList<Test>(2);         values.add(new Test(1, 2));         values.add(new Test(3, 4));          List<Test> readOnly = Collections.unmodifiableList(values);         for (Test t : readOnly) {             t.a = 5;         }          for (Test t : values) {             System.out.println(t.a);         }     }  } 

    This outputs:

    5 5 

    Important considerations from @WMR answser.

    It depends on if the threads that are reading your collection are started before or after you’re filling it. If they’re started before you fill it, you have no guarantees (without synchronizing), that these threads will ever see the updated values.

    The reason for this is the Java Memory Model, if you wanna know more read the section ‘Visibility’ at this link: http://gee.cs.oswego.edu/dl/cpj/jmm.html

    And even if the threads are started after you fill your collection, you might have to synchronize because your collection implementation could change its internal state even on read operations (thanks Michael Bar-Sinai, I didn’t know such collections existed).

    Another very interesting read on the topic of concurrency which covers topics like publishing of objects, visibility, etc. in much more detail is Brian Goetz’s book Java Concurrency in Practice.

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

Sidebar

Related Questions

I would like to ask one interested (for me) question. What collection is the
I bind a collection ObservableCollection<Foo> to a dependency property on my controller, but I
I have a list that I need to fill using a JSON collection of
I am trying to fill a form in a php application from a C#
When using wireframe fill mode in Direct3D, all rectangular faces display a diagonal running
I know how to fill an std::vector with non-trivial initial values, e.g. sequence numbers:
I want to fill a map with class name and method, a unique identifier
What would be the best way to fill a C# struct from a byte[]
What would be the best way to fill an array from user input? Would
Edit: I am using SqlDataAdapters to fill the data sets. Sorry--I should have been

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.