java - Spring SimpleThreadScope in a web app : part of container pool? -



java - Spring SimpleThreadScope in a web app : part of container pool? -

have service exposes crypto functions. don't need clean nor want objects created every time/ every session. need separate object per thread.

in web app - scope web container's thread pool ?

is same in spring 3 , 4 implementation?

another place plan utilize cache simpledateformat objects. 1 time again don't need clean method.

since version 3.0, spring has basic notion of thread scope : simplethreadscope. looks can feet ask, has limitations :

it not registered default containers must explicitely be it performs no cleanup on beans.

if can accomodate limitations, can register scope programatically :

scope threadscope = new simplethreadscope(); appcontext.getbeanfactory().registerscope("thread", threadscope);

or in xml config :

<bean class="org.springframework.beans.factory.config.customscopeconfigurer"> <property name="scopes"> <map> <entry key="thread"> <bean class="org.springframework.context.support.simplethreadscope"/> </entry> </map> </property> </bean>

this works same in spring 3 , spring 4. if want inject thread scoped bean in singleton bean, have declare aop scoped-proxy on :

<bean id="bar" class="x.y.bar" scope="thread"> <property name="name" value="rick"/> <aop:scoped-proxy/> </bean> <bean id="foo" class="x.y.foo"> <property name="bar" ref="bar"/> </bean>

(all examples spring framework reference documentation).

if have cleanup, can @ document spring illustration custom thread scope module shows enhanced version of simplethreadscope.

but not sure want that, unless threads continuously utilize thread scoped beans, or memory not concern. because in design pattern, if 1 session @ time needs bean, served several threads (assuming other requests not need bean), threads different instance of bean, whereas pool 1 instance have been used.

you find illustration of using commonspooltargetsource apache mutual pools in other post how pool objects in spring?. extract post :

<bean id="simplebeantarget" class="com.bean.simplebean" scope="prototype"/> <bean id="pooltargetsource" class="org.springframework.aop.target.commonspooltargetsource"> <property name="targetbeanname" value="simplebeantarget" /> <property name="maxsize" value="2" /> </bean> <bean id="simplebean" class="org.springframework.aop.framework.proxyfactorybean"> <property name="targetsource" ref="pooltargetsource" /> </bean>

the illustration utilize proxyfactorybean give aop proxy allow injection of simplebean in singleton bean, provided injected interface.

java spring web-applications

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -