我们必须在这里我们使用了弹簧IOC的应用程序。我们在applicationContext.xml中配置了dataSource bean,并在其他bean定义中引用它。数据源初始化启动
数据源bean认定中的样子:
<bean id="dbDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url"
value="jdbc:oracle:oci:@TESTDB" />
<property name="username" value="TESTUSER" />
<property name="password" value="TESTPWD" />
<property name="initialSize" value="50" />
<property name="maxActive" value="40" />
<property name="maxIdle" value="10" />
<property name="minIdle" value="10" />
<property name="maxWait" value="-1" />
</bean>
<bean id="serviceDAO" class="com.test.impl.ServiceDAOImpl">
<property name="dataSource" ref="dbDataSource" />
</bean>
ServiceDAOImpl如下所示:
public class ServiceDAOImpl implements ServiceDAO {
private JdbcTemplate jdbcTemplate;
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public ValueObj readValue(String key) {
String query = "SELECT * FROM SERVICE_LOOKUP WHERE KEY=?";
/**
* Implement the RowMapper callback interface
*/
return (ValueObj) jdbcTemplate.queryForObject(query,
new Object[] { key }, new RowMapper() {
public Object mapRow(ResultSet resultSet, int rowNum)
throws SQLException {
return new ValueObj(resultSet.getString("KEY"),
resultSet.getString("VALUE"));
}
});
}
public ServiceDAOImpl() {
}
}
现在,在服务器启动时注入正在发生细微而当我们使用数据源中serviceDAOImpl的连接正在发生。但是,第一次进行数据库调用需要大约3分钟才能获得响应。我想,这是因为池创建的第一个电话中进行,我们在applicationConext.xml
设置参数"initialSize" = 50
。
因此,为了避免这一点,我们需要能够在应用程序启动时创建本身可直接使用的池的方式。
请建议。如果需要澄清,请告知我。
问候 Saroj
春天确实渴望单身bean创建/默认初始化所以创建池时被读取并配置了环境。还有其他一些事情必须导致延迟。 – soulcheck 2012-01-16 12:34:42
Soulcheck嗨, 许多感谢名单为您回复。但我已经用initialSize参数值为1测试了代码,时间缩短为6秒。 – user1061771 2012-01-16 13:19:29