java - How to create a MAP that has an application scope? And Where to declare it? -


i need create map has application scope. , so, if user1 add map object using method1 of class1, user2 find new objects using method2 of class2.

i know there annotation :

@applicationscoped 

but, don't know map should declared or used, make have same state @ anytime , anywhere in application deployment time.

an example representing class map declared , method of class using it, helpful.

declare cdi bean provide map consumption:

@named @applicationscoped public class applicationscopedbean {     private map<keyclass, valueclass> map;     @postconstruct     public void init() {         //initialize map , data here         map = new concurrenthashmap<>();         map.put(..., ...);         //...     }     //provide getter map     public map<keyclass, valueclass> getmap() {         return this.map;     } } 

now, bean can injected in clients , can show data in view.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -