简体   繁体   English

与在代码中手动创建数据源相比,为什么在Jboss EAP 6.4中的standalone.xml中创建数据源具有更长的响应时间

[英]Why creating datasource in standalone.xml in Jboss EAP 6.4 is giving longer response time as compared to when datasource is created in code manually

I have a web application where i am using jboss EAP 6.4. 我在使用jboss EAP 6.4的Web应用程序中。 There i am using two configurations for creating datasource. 我在这里使用两种配置来创建数据源。 Datasource is defined in standalone file also and if while creating datasource object any exception is thrown then data source is created manually in code. 数据源也是在独立文件中定义的,如果在创建数据源对象时抛出任何异常,则将在代码中手动创建数据源。 Code for the same is given below: 相同的代码如下:

@Bean
    public DataSource getDataSource() {
        try {
            Object object = new JndiTemplate().lookup(JNDI);
            return DataSource) object;
        } catch (NamingException e) {
            DriverManagerDataSource dataSource = new DriverManagerDataSource();
            dataSource.setDriverClassName(---);
            dataSource.setUrl(---);
            dataSource.setUsername(---);
            dataSource.setPassword(---);

            return dataSource;
        }
    }

Here is my standalone.xml snippet 这是我的standalone.xml代码段

<datasource jta="false" jndi-name="xyz" pool-name="xyDatasource" enabled="true" use-ccm="false">
                    <connection-url>jdbc:oracle:thin:@localhost:1521:xe</connection-url>
                    <driver>OracleJDBCDriver</driver>
                    <pool>
                        <min-pool-size>20</min-pool-size>
                        <max-pool-size>30</max-pool-size>
                        <use-strict-min>true</use-strict-min>
                        <flush-strategy>FailingConnectionOnly</flush-strategy>
                    </pool>
                    <security>
                        <user-name>abc</user-name>
                        <password>xyz</password>
                    </security>
                    <validation>
                        <validate-on-match>false</validate-on-match>
                        <background-validation>false</background-validation>
                    </validation>
                    <statement>
                        <share-prepared-statements>false</share-prepared-statements>
                    </statement>
       </datasource>

The problem here is when connection is created successfully using standalone version datasource at that time the response time for all the requests are pretty high as compared to when its is created in code in catch condition. 这里的问题是,当使用独立版本数据源成功创建连接时,与在捕获条件下的代码中创建连接时相比,所有请求的响应时间都很高。

I searched a lot but didn't find any reason for it. 我进行了很多搜索,但没有找到任何原因。

As per my understanding, when code is getting connection via datasource defined in standlone.xml file, it gets connection from pool defined in configuration. 据我了解,当代码通过standlone.xml文件中定义的数据源获得连接时,它从配置中定义的池中获得连接。 It doesn't have to take direct connection from database every time while performing operations. 执行操作时,不必每次都从数据库直接建立连接。

However when connecting to database directly using code, its code's responsibility to get connection from database and then do lookup. 但是,当直接使用代码连接到数据库时,其代码负责从数据库获得连接并进行查找。

Refer https://docs.oracle.com/javase/tutorial/jdbc/basics/sqldatasources.html 请参阅https://docs.oracle.com/javase/tutorial/jdbc/basics/sqldatasources.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM