开发者

How to create a LinkedBlockingQueue<Runnable> as a Spring bean?

开发者 https://www.devze.com 2023-03-14 02:00 出处:网络
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:

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

精彩评论

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