靜態的Class instance如 Runtime r = Runtime.getRuntime();
在spring 裡可以這樣設
<bean id="runTime" class="java.lang.Runtime" factory-method="getRuntime"/>
然後int localMaxThread = r.availableProcessors();
我們可以這樣設定
<bean id="localMaxThread" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="targetObject"> <ref bean="runTime"/> </property> <property name="targetMethod"> <value>availableProcessors</value> </property> </bean>
最後完整的xml 設定例子如下
<bean id="limitedQueue" class="com.gfactor.emd.concurrent.LimitedQueue"> <constructor-arg index="0"> <value>1</value> </constructor-arg> </bean> <bean id="runTime" class="java.lang.Runtime" factory-method="getRuntime"/> <bean id="localMaxThread" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="targetObject"> <ref bean="runTime"/> </property> <property name="targetMethod"> <value>availableProcessors</value> </property> </bean> <bean id="fetchEmlMessagethreadPoolExecutor" class="java.util.concurrent.ThreadPoolExecutor"> <constructor-arg type="int" ref="localMaxThread"></constructor-arg> <constructor-arg type="int" value="12"></constructor-arg> <constructor-arg type="long" value="300"></constructor-arg> <constructor-arg type="java.util.concurrent.TimeUnit" value="SECONDS" ></constructor-arg> <constructor-arg type="java.util.concurrent.BlockingQueue" ref="limitedQueue"></constructor-arg> </bean>
沒有留言:
張貼留言