Oracle JDBC flush共享池无法正常工作

时间:2016-11-30 11:03:26

标签: java oracle jdbc oracle11g

我有以下和平的java代码,可以比较这两个SQL查询的性能。 getNamedStatistics()打印v $ session表中的一些列,如一致获取,执行计数等。

虽然我无法刷新oracle的内存,所以我可以比较这两个查询的性能。

        clearOracleMemory();
        start = System.nanoTime();
        System.out.println("Named statistics --> " + getNamedStatistic(statistics, conn));
        query1UsingStatement(conn);
        System.out.println("Named statistics --> " + getNamedStatistic(statistics, conn));
        end = System.nanoTime();
        System.out.println("Took: " + ((end - start) / 1000000) + "ms");

        clearOracleMemory();
        start = System.nanoTime();
        System.out.println("Named statistics --> " + getNamedStatistic(statistics, conn));
        query2UsingStatement(conn);
        System.out.println("Named statistics --> " + getNamedStatistic(statistics, conn));
        end = System.nanoTime();
        System.out.println("Took: " + ((end - start) / 1000000) + "ms");

ClearOracleMemory看起来像这样:

    private static void clearOracleMemory() {
        try {
            PreparedStatement stmt = conn.prepareStatement("alter system flush shared_pool");
            ResultSet rs = stmt.executeQuery();
            System.out.println("shared pool flushed");
        }
        catch (SQLException e) {
            System.out.println("error clearing shared pool");
            System.out.println(e.getMessage());
        }
    }

示例输出:

shared pool flushed
Named statistics --> {CPU used by this session=45, consistent gets=5613, parse count (total)=194, parse time elapsed=14, parse time cpu=14, execute count=1544}

Named statistics --> {CPU used by this session=326, consistent gets=936322, parse count (total)=724, parse time elapsed=58, parse time cpu=60, execute count=3651}
Took: 3676ms

shared pool flushed
Named statistics --> {CPU used by this session=344, consistent gets=942088, parse count (total)=851, parse time elapsed=69, parse time cpu=73, execute count=5319}

Named statistics --> {CPU used by this session=2374, consistent gets=1019846, parse count (total)=20975, parse time elapsed=1728, parse time cpu=1732, execute count=26948}
Took: 28038ms

1 个答案:

答案 0 :(得分:4)

是什么让您认为共享池不会被刷新?

我怀疑您是否混淆了共享池和会话统计信息?会话统计数据统计了会话的不同资源消耗情况。刷新共享池会影响会话消耗的资源数量(因为它需要解析语句),但这显然不会重置资源消耗计数器。

我建议您重新审视所分配的读数,并详细说明。

祝你好运

你友好的老师,你提出了你所询问的练习