Singleton in Spring to avoid reinvent wheels
来源:互联网 发布:京东java在线笔试题 编辑:程序博客网 时间:2024/05/14 09:27
Sometimes you run into below piece of code which would call a object to do something, it costs some effort to actually construct the new object every time you invoke this caller method, so to avoid this, you can actually make this object as a singleton if it's thread safe and no other conflicts.
private void doSomething(String param) { //.... serviceProxy.doSomethingForCaller(param); }
Spring.xml
<bean id="serviceProxy" class="service.ServiceProxyImpl"> <constructor-arg index="0" value="${host}"/> <constructor-arg index="1" value="${port}"/> </bean>
or you can create a factory method which is responsible for creating the object.
<bean id="hongKongTimeZone" class="java.util.TimeZone" factory-method="getTimeZone"> <constructor-arg value="Asia/Hong_Kong"/> </bean>
- Singleton in Spring to avoid reinvent wheels
- How to avoid Unicode pitfalls in Mojolicious
- How to avoid using() mistake in C#?
- Memory leaks in C++ and how to avoid them
- How to avoid the "enumeral mismatch" error in eikmenup.h
- How to avoid “!= null” statements in Java?
- How to avoid memory leaks in iPhone applications
- how to avoid css and js cache in UIWebView
- 3 Good Reasons to Avoid Arrays in Java Interfaces
- avoid cache in jsp
- avoid jstl in loop
- Avoid @throws in javadoc
- How to avoid Conflict
- Memory usage in a 32bit Windows environment (how to avoid ORA-4030 /ORA-12500s
- Bind: Address Already in Use Or How to Avoid this Error when Closing TCP Connections
- [iOS开发站在巨人肩膀上]之How to avoid memory leaks in iPhone applications
- How To Avoid ORA-04030/ORA-12500 In 32 Bit Windows Environment [Video] [ID 373602.1]
- How to detect and avoid memory and resources leaks in .NET applications()
- 为什么我们说海量数据处理技术会火
- WC 2010 efield 能量场
- vi命令
- Struts2学习之类型转换
- ffmpeg
- Singleton in Spring to avoid reinvent wheels
- 任务二
- 99se 封装属性设置大全
- PC/UVa 110706/10042 Smith Numbers
- C# 事件解析
- android View
- 软件质量的度量
- 清华大学考博 综合考试
- Android应用开发之实现图片的拖拽显示