Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在spring应用程序中,第一个查询(不管任何sql语句)的执行时间超过12秒。数据库是oracle_Java_Spring_Oracle_Performance - Fatal编程技术网

Java 在spring应用程序中,第一个查询(不管任何sql语句)的执行时间超过12秒。数据库是oracle

Java 在spring应用程序中,第一个查询(不管任何sql语句)的执行时间超过12秒。数据库是oracle,java,spring,oracle,performance,Java,Spring,Oracle,Performance,我有一个简单的spring独立应用程序,其中我使用apache基本数据源类创建自己的数据源。然后将数据源传递给命名参数jdbc模板 第一个查询的执行时间总是超过12秒,然后第二个查询就可以了。(我相信这是因为它第一次建立了联系)。但这会影响应用程序的性能,因为它本应每5分钟运行一次,但一个作业本身所花费的时间比平时多。有人能告诉我可以做些什么来提高性能吗。代码如下: ---数据源创建和模板对象创建-------- -----第一次查询调用 SiteDetails sd = null;

我有一个简单的spring独立应用程序,其中我使用apache基本数据源类创建自己的数据源。然后将数据源传递给命名参数jdbc模板

第一个查询的执行时间总是超过12秒,然后第二个查询就可以了。(我相信这是因为它第一次建立了联系)。但这会影响应用程序的性能,因为它本应每5分钟运行一次,但一个作业本身所花费的时间比平时多。有人能告诉我可以做些什么来提高性能吗。代码如下:

---数据源创建和模板对象创建--------

-----第一次查询调用

SiteDetails sd = null; 
        try{
            String fetchSiteDtls = "SELECT SITE_STATUS_ID, SITE_ENABLED, ITERATION_ID, UPDATED_DATE "+ 
                "FROM DSP_SITE_DETAILS WHERE SITE_ID =:siteid";

        MapSqlParameterSource parameterSource = new MapSqlParameterSource();
        parameterSource.addValue("siteid", siteId);
        if(log.isDebugEnabled())
        log.debug("fetchSiteDetails:query:" +fetchSiteDtls);
        long start = System.currentTimeMillis();

        sd = namedParJdbcTempl.queryForObject(fetchSiteDtls, parameterSource, (rs, rowNum)->{                           
                    SiteDetails siteDetails = new SiteDetails();
                    siteDetails.setSiteStatus(rs.getInt("SITE_STATUS_ID"));
                    siteDetails.setSiteEnabled(rs.getString("SITE_ENABLED"));
                    siteDetails.setIterationId(rs.getInt("ITERATION_ID"));
                    siteDetails.setStatusUpdateTimeStamp(rs.getTimestamp("UPDATED_DATE"));                  
                    return siteDetails;});
        sd.setSiteId(siteId);
            long end = System.currentTimeMillis();
            if(log.isDebugEnabled())
            log.debug("Total time for executing query: " +(end - start));               
            return sd;

Question updated to state: Oracle is the database and query is already ran in sql client to run less than 1 sec. Even tried different sql. Tried different ways of connecting to datasource like spring datasource, apache basic datasource, HikerCP datasource, finally removed datasource itself and tried with normal jdbc connection with driver manager. I added execution time for every step and got that the connection object is taking 12 - 20 secs to connect. 

Can someone from oracle community help with a suggestion as can there be any problem with the oracle setup or something else?

您在哪里计算查询所用的时间?有很多参数可以配置,例如活动连接,使用示例查询和最大活动时间测试它们。阅读文档并使用适合您情况的参数。e、 我认为DBCP已经少用了好几天了,所以请选择更好的库,比如。@VikramSingh:我编辑了这篇文章,在代码中添加了时间戳。你不是在计算时间correctly@VikramSingh:抱歉,我刚刚编辑了查询。更改了出于测试目的而初始化的第一个查询调用。
SiteDetails sd = null; 
        try{
            String fetchSiteDtls = "SELECT SITE_STATUS_ID, SITE_ENABLED, ITERATION_ID, UPDATED_DATE "+ 
                "FROM DSP_SITE_DETAILS WHERE SITE_ID =:siteid";

        MapSqlParameterSource parameterSource = new MapSqlParameterSource();
        parameterSource.addValue("siteid", siteId);
        if(log.isDebugEnabled())
        log.debug("fetchSiteDetails:query:" +fetchSiteDtls);
        long start = System.currentTimeMillis();

        sd = namedParJdbcTempl.queryForObject(fetchSiteDtls, parameterSource, (rs, rowNum)->{                           
                    SiteDetails siteDetails = new SiteDetails();
                    siteDetails.setSiteStatus(rs.getInt("SITE_STATUS_ID"));
                    siteDetails.setSiteEnabled(rs.getString("SITE_ENABLED"));
                    siteDetails.setIterationId(rs.getInt("ITERATION_ID"));
                    siteDetails.setStatusUpdateTimeStamp(rs.getTimestamp("UPDATED_DATE"));                  
                    return siteDetails;});
        sd.setSiteId(siteId);
            long end = System.currentTimeMillis();
            if(log.isDebugEnabled())
            log.debug("Total time for executing query: " +(end - start));               
            return sd;

Question updated to state: Oracle is the database and query is already ran in sql client to run less than 1 sec. Even tried different sql. Tried different ways of connecting to datasource like spring datasource, apache basic datasource, HikerCP datasource, finally removed datasource itself and tried with normal jdbc connection with driver manager. I added execution time for every step and got that the connection object is taking 12 - 20 secs to connect. 

Can someone from oracle community help with a suggestion as can there be any problem with the oracle setup or something else?