开发者

Create ObjectPool in Spring

I have a class


class ObjPool {
 MyObject getObject() {...}
 void returnObject() {...}
 int getUsedCount() {.开发者_C百科..}
}

How can we use Spring framework so that it would provide only one copy of this factory to all (web) applications and so that each and every application use the same ObjPool?

I mean if app A gets an object from this ObjPool, then all other applications that invoke getUsedCount() will see that value decremented.


In Spring each bean is a singleton by default, which means - one instance of the bean per ApplicationContext. This is NOT one per container, but one per web application.

http://blog.springsource.com/2007/06/11/using-a-shared-parent-application-context-in-a-multi-war-spring-application/ gives an example of how to load an ApplicationContext at the EAR level and share across all wars.


You could just google for "spring export to jndi"

http://maestro-lab.blogspot.com/2009/01/how-to-export-spring-managed-bean-to.html

org.springframework.jndi.JndiTemplate is a good place to start

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜