1

我有一个使用 hibernate 进行 O/R 映射的 java 应用程序,我还使用了与 hibernate 一起提供的 c3p0 连接池。数据库是甲骨文。

这是在我的hibernate.cfg.xml

<property name="hibernate.c3p0.min_size">3</property>
<property name="hibernate.c3p0.max_size">5</property>
<property name="hibernate.c3p0.max_statements">20</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.idleTestPeriod">120</property>        

这就是我获得休眠会话的方式:

public class HibernateUtil {
    private static Logger log = Logger.getLogger(HibernateUtil.class);
    private static final SessionFactory sessionFactory;

    private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = new Configuration().configure(CONFIG_FILE_LOCATION).buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            log.fatal("Initial SessionFactory creation failed." + ex.getMessage());
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}

但是当我SELECT * FROM V$SESSION WHERE machine='xxx';在 Oracle 中运行时,连接数可以达到 20,大于max_size.

最大连接数在 Linux 环境中不起作用,但在 Unix 和 Windows 中起作用。Linux 中的任何设置都需要调整吗?

我还怀疑某处有应用程序的缓存,就像我之前设置max_size的 20 个一样。我在 Tomcat 5.5 中运行该应用程序。但是我不知道Tomcat中有这样的应用程序缓存。

另一个信息:我正在运行 Linux 2.6.9-34.ELsmp。Red Hat Enterprise Linux AS release 4 (Nahant Update 3)

谢谢。

4

1 回答 1

0

我猜你有额外的数据库会话不是从你的应用程序打开的。例如,应该有一个额外的连接——你用来运行SELECT语句的那个​​。

于 2011-01-11T05:24:35.417 回答