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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:36:32+00:00 2026-06-01T17:36:32+00:00

I have an @ApplicationScoped bean for all users, that stores the ids-> names &

  • 0

I have an @ApplicationScoped bean for all users, that stores the ids-> names & vice versa in Trove & java.util maps.

I just build the maps once at construction of bean or (in case of manual refresh by the website admin).

Inside the bean methods, I am just using the get() with the maps, so not modifying the map. Is this going to be thread safe since it is used only for ready purposes? I am not sharing the maps with any other beans outside & not modifying the maps(adding/removing entries) anytime in my code.

Also, Is it neccesary in this case to make the fields final ?

Bean code as follows:

@ApplicationScoped
@ManagedBean(name="directory", eager=true)
public class directory {

    private static TIntObjectHashMap<String> idsToNamesMap;
    private static TreeMap<String, Integer> namesToIdsMap;

    @PostConstruct
    public void buildDirectory(){
        // building directory here ....
    }

    public String getName(int topicId){
        return idsToNamesMap.get(topicId);
    }    

    public List<Entry<String, Integer>> searchTopicsByName(String query){
        return new ArrayList(namesToIdsMap.subMap(query, true, query+"z", true).entrySet());
    }        
}

  • 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-01T17:36:33+00:00Added an answer on June 1, 2026 at 5:36 pm

    You don’t have to declare them volatile or protect with any kind of synchronization in this case. As long as the constructing thread will build them and synchronize with the main memory.

    For that the constructing thread need just to make a single write to a volatile variable or enter/exit a synchronization lock. This will pass a memory barrier and all local thread data will be in the main thread. Then it will be safe for all other threads to read this data.

    Even more – unnecessary volatile or synchronization block – costs a serious performance penalty – on each access to the variable it will pass the memory barrier – which is an expensive operation

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

Sidebar

Related Questions

In my application, I have an @ApplicationScoped CDI bean to store some information from
I have a dataTable which has a value of a bean class which looks
I have a fairly standard Spring/Hibernate Java project where I need to set a
Have a look at one of my websites: moskah.com The problem is that it
I have an application that shows some data in p:DataTable.... This table is accessible
I have written a WCF service that I am hosting in IIS7 as a
Have written all the code in a silverlight class library (dll) and linked this
Have a problem that seems easy on paper but i'm having a big problem
In my applicatoin I have a application scoped bean, which I call it like
I have a problem to refresh or reload an application scoped managed bean. It

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.