开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜