How to create a LinkedBlockingQueue<Runnable> as a Spring bean?
I need to pass a LinkedBlockingQueue as a bean to a number of other开发者_运维技巧 beans. Is it possible to define one in XML. It's normal definition is simply:
new LinkedBlockingQueue<Runnable>()
You can just do that:
<bean id="queue" class="java.util.concurrent.LinkedBlockingQueue" />
I don't think you can explicitly say that it holds Runnable instances as the queue will be created at run time where Java generics is not visible.
EDIT: You can also pass constructor arguments:
<bean id="queue" class="java.util.concurrent.LinkedBlockingQueue" >
<constructor-arg type="int"><value>10</value></constructor-arg>
</bean>
This will limit the queue size to 10.
精彩评论