gpt4 book ai didi

java - Oracle JDBC 刷新共享池不工作

转载 作者:行者123 更新时间:2023-11-29 08:40:08 24 4
gpt4 key购买 nike

我有以下 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

最佳答案

是什么让您认为共享池没有被刷新?

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

我建议您重新查看分配的阅读 Material ,其中有一些详细说明。

最好的问候

你友善的老师,他制定了你所要求的练习

关于java - Oracle JDBC 刷新共享池不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40886689/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com