java - multiple singleton beans referencing the same class -
i have java class lets 'class1' holds concurrenthashmap (to used cache) , functions update , remove entries in map.this class not designed singleton class. having discussion colleague, couldnt decide due couple of posts read on internet.i asking if okay this-
<bean id="reqrespcachemgr1" class="gravity.applications.rfqservice.reqrespgtwy.utility.reqrespcachemanager" scope="singleton"> </bean> <bean id="reqrespcachemgr2" class="gravity.applications.rfqservice.reqrespgtwy.utility.reqrespcachemanager" scope="singleton"> </bean> <bean id="reqrespcachemgr3" class="gravity.applications.rfqservice.reqrespgtwy.utility.reqrespcachemanager" scope="singleton"> </bean>
i trying create 3 singleton instances of same class..i think doesnt spoil meaning of singleton-ness because talking singleton scope in spring bean factory context , not class loader context.. know there alternate ways this.. having 3 concurrenthash maps in same class , using 1 singleton bean reference ,there trying create update , remove methods 3 maps in same class.
i hope didnt make confusing wanna know approach.i afraid im making improper use of design patterns..
let me know if question unclear
it seems need not singleton prototype
<bean id="reqrespcachemgr" class="gravity.applications.rfqservice.reqrespgtwy.utility.reqrespcachemanager" scope="prototype" /> class b1 { @autowire reqrespcachemanager cachemanager; } class b2 { @autowire reqrespcachemanager cachemanager; } class b3 { @autowire reqrespcachemanager cachemanager; }
all 3 beans new instance of reqrespcachemanager
Comments
Post a Comment