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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:31:40+00:00 2026-06-06T00:31:40+00:00

class EverythingMustBeInAClass { private final int i = 42; private final int[] a =

  • 0
class EverythingMustBeInAClass
{
    private final int i = 42;
    private final int[] a = {2, 3, 5, 7, 11, 13, 17, 19};
}

The fact that i is declared final guarantees that all threads see the same int value 42 (instead of 0).

The fact that a is declared final guarantees that all threads see the same array reference.

But how do I make sure that all threads see the same array elements (instead of 0s)? Do I have to synchronize access to the array, even if I never intend to change the array elements later on?

  • 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-06T00:31:41+00:00Added an answer on June 6, 2026 at 12:31 am

    final guarantees not only that the array reference is seen but also that the object itself has been fully constructed and initialized. So the values in the array will also be seen by all threads.

    Here’s a good link on the subject: Thread-safety with the Java final keyword

    To quote:

    The fields on any object accessed via a final reference are also guaranteed to be at least as up to date as when the constructor exits.

    However, it is important to note that the a array is not immutable so, for example, you could set a[0] = 10 and that update would not be synchronized. But as long as you don’t change any values in a you should be good.

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

Sidebar

Related Questions

class foo { public: void set(const int a) {b=a;} private: int b; }; Here
class token { private: char m_chIcon; //actual ascii char that shows up for this
class Foo { private: int m_i; public: Foo(int i) : m_i(i) {} }; class
Class 1 private void checkDuplicateCustomer(BulkCustomerVO bulkCustomerVO) { PagedDuplicateCustomerVO duplicateCustomerVO = new PagedDuplicateCustomerVO(); duplicateCustomerVO.setCustomer(bulkCustomerVO.getCustomerVO()); duplicateCustomerVO
class X { int i; public: X() { i = 0; } void set(int
class A{ virtual int foo1(int a){ return foo1_1(a,filler(a)); } template<typename FunctionPtr_filler> int foo1_1(int a,
class a{ public void foo(int a){ System.out.println(super); } } class b extends a{ public
{ class Program { static void Main(string[] args) { int id = 0, stock
class Test extends JPanel implements MouseListener { private JButton b1, b2, b3, b4; public
Class Account extends CI_Model { private $tbl_rest = array(); private $tbl_fields = array('bs_id', 'bs_name',

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.