最近在做调用接口的JAVA代码,其中用到了className object=new className();
但每次调用时都会生产一次对象,效率低.
可以用Spring来解决:
在JAVA代码中:
在BeanUtil.java中:
但每次调用时都会生产一次对象,效率低.
可以用Spring来解决:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="beanName" class="...">
</bean>
</beans>
在JAVA代码中:
className oProxy = (className)BeanUtil.getInstance().getBean(context, "beanName", false);
在BeanUtil.java中:
public static synchronized BeanUtil getInstance()
{
if(instance == null)
instance = new BeanUtil();
return instance;
}