Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7073937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:59:24+00:00 2026-05-28T05:59:24+00:00

We have an application where we have used spring for IOC. We have the

  • 0

We have an application where we have used spring for IOC. We have the dataSource bean configured in applicationContext.xml and that is referenced in other bean definations.

The dataSource bean defination looks like:

    <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 looks as follows:

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() {

    }
}

Now, at the server start up injection is happening fine and when we use the dataSource in serviceDAOImpl the connection is happening fine. But the very first time the database call is made it takes around 3 mins to get the response back. I think this is because the pool creation is done during the first call and we have set the parameter "initialSize" = 50 in applicationConext.xml.

So, to avoid this we need a way in which the pool can be created during the application startup itself and can be used directly.

Please suggest. Let me know if any clarification required.

Regards
Saroj

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:59:25+00:00Added an answer on May 28, 2026 at 5:59 am

    There’s a work-around for this .You could force jdbcTemplate to use the
    DB connection at startup. See the link here for detailed explanation .

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
       <constructor-arg index="0" ref="dataSource"/>
       <constructor-arg index="1" value="false"/>
    </bean>
    

    The second constructor-arg is the lazy Init flag.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large application spread across multiple Spring bean definition xml files. In
I have used spring framework 3 for my application. Everything is ok while developed
I have an application that used Macro. In this macro I would like to
Say I have an application that used an ORM (I am thinking of nHibernate
I have an application that is used on several hundred computers across the company
I have an application that was originally written in Borland C++ and used a
I have an application where I have to use Spring to load a bean
I have developed an application with Spring. I've a bean to create a thread,
I am writing a Spring Restful webservices application using Spring MVC. I have used
I have an application where a property placeholder is used to read properties, configured

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.