Java 带Hibernate和C3P0配置的Spring引导。连接池已耗尽。(Oracle 10g方言)

Java 带Hibernate和C3P0配置的Spring引导。连接池已耗尽。(Oracle 10g方言),java,oracle,hibernate,spring-boot,c3p0,Java,Oracle,Hibernate,Spring Boot,C3p0,会话工厂是自动连接的,并且编写了一个简单的代码,其中包含打开和关闭会话 hibernate.dialect=org.hibernate.dialect.Oracle10gDialect hibernate.show_sql=true hibernate.format_sql=true hibernate.cache.use_second_level_cache=true hibernate.cache.use_query_cache=true hi

会话工厂是自动连接的,并且编写了一个简单的代码,其中包含打开和关闭会话

    hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
    hibernate.show_sql=true
    hibernate.format_sql=true
    hibernate.cache.use_second_level_cache=true
    hibernate.cache.use_query_cache=true
    hibernate.generate_statistics=true
    cache.provider_class=org.hibernate.cache.EhCacheProvider
    initialPoolSize=5
    minPoolSize=100
    maxPoolSize=250
    acquireIncrement=5
    maxStatements=100
    acquireRetryAttempts=10
    acquireRetryDelay=1000 
    breakAfterAcquireFailure=false
    maxIdleTime=1800
public类基本身份验证impl{
私有静态SessionFactory SessionFactory;
公共静态SessionFactory getSessionFactory()
{
返回工厂;
}
公共静态void setSessionFactory(SessionFactory SessionFactory)
{
BasicAuthenticationImpl.sessionFactory=sessionFactory;
}
}
公共类模块1
{
@自动连线
私人会话工厂会话工厂;
私有会话=null;
@凌驾
公共作废进程(列出routableProcessObjects)
异常
{
尝试
{
session=sessionFactory.openSession();
session.flush();
canonicalMessage=
lookupprocesser.processInput(canonicalMessage,
常量(L1_查找_缓存,会话);
}
捕获(例外情况除外)
{
}
最后
{
if(session!=null&&session.isOpen()){
session.close();
}
}
}
}
公共类Lookupprocesser{
公共CanonicalMessage processInput(CanonicalMessage CanonicalMessage,
字符串缓存查找,会话会话)引发DataInsightsCommonException
{
lookupSearchForL1(规范消息、会话、缓存查找);
返回规范消息;
}
}
公共类查询{
通过MatchKey1和MatchKey2进行公共列表搜索(会话
会话,字符串匹配键1,字符串匹配键2)抛出
DataInsightsCommonException
{
查询;
列表t=null;
query=session.createQuery(“从作为odt的数据中,其中odt.Key1是
null和odt.Key2=:Key2“;
query.setParameter(Constants.KEY2,KEY2);
query.setCacheable(true);
终端=(List)query.List();
return(null!=t&&!t.isEmpty())?t:null;
}
}
Session对象在所有类和对象之间共享,我编辑了下面的代码,BasicAuth类创建了SessionFactory
模块1将调用LookupProcessor,后者将调用查询类。我们正在关闭模块1上的会话。

“编写了一个包含打开和关闭会话的简单代码。”请将此代码添加到问题中,好吗?添加了此代码。如果模块1的任何实例在线程之间共享,则此代码中存在危险。如果您定义
Session=null
作为局部变量,就在
进程(…)
中的
try
块上方。(这里可能还有其他问题——您正在吞咽异常,您可能希望至少在某个地方记录它们;在genetal中,我不确定这是组织事情的最佳方式——但最有可能是共享的
会话
对象导致了您的池耗尽。)谢谢,即使我也这么认为。所以这里的事情是我们有一个webapp模块,它可以覆盖应用程序上下文,创建bean和所有东西。dao完全位于单独的模块中,因此我们正在传递会话对象。您的会话对象在
模块1中是
私有的
,并且只在
进程(…)
中使用,因此无论您如何组织事情,如果将
会话
作为局部变量获取,并将其作为成员变量删除,则外部世界将无法区分,从而防止对
进程(…)
的多次调用在引用的对象关闭之前覆盖
会话
变量的可能性。
    <bean id="DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="${jdbc.driverClassName}"></property name>
    <property name="jdbcUrl" value="${ondot.jdbc.url}"></property name>
    <property name="user" value="${jdbc.user}"></property name>
    <property name="password" value="${jdbc.password}"></property name>
    <property name="initialPoolSize" value="${initialPoolSize}" /></property name>
    <property name="minPoolSize" value="${minPoolSize}"></property name>
    <property name="maxPoolSize" value="${maxPoolSize}"></property name>
    <property name="acquireIncrement" value="${acquireIncrement}"></property name>
    <property name="maxStatements" value="${maxStatements}"></property name>
    <property name="acquireRetryAttempts" value="${acquireRetryAttempts}"></property name>
    <property name="acquireRetryDelay" value="${acquireRetryDelay}"> </property name>
    <property name="breakAfterAcquireFailure" 
     value="${breakAfterAcquireFailure}"></property name>
    <property name="maxIdleTime" value="${maxIdleTime}"> </property name>
    hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
    hibernate.show_sql=true
    hibernate.format_sql=true
    hibernate.cache.use_second_level_cache=true
    hibernate.cache.use_query_cache=true
    hibernate.generate_statistics=true
    cache.provider_class=org.hibernate.cache.EhCacheProvider
    initialPoolSize=5
    minPoolSize=100
    maxPoolSize=250
    acquireIncrement=5
    maxStatements=100
    acquireRetryAttempts=10
    acquireRetryDelay=1000 
    breakAfterAcquireFailure=false
    maxIdleTime=1800
    public class BasicAunthenticationImpl {
    private static SessionFactory   sessionFactory;
    public static SessionFactory getSessionFactory()
    {
    return sessionFactory;
    }

   public static void setSessionFactory(SessionFactory sessionFactory)
   {
    BasicAunthenticationImpl.sessionFactory = sessionFactory;
   }
   }

   public class Module1 
   {
   @Autowired
   private SessionFactory   sessionFactory;
   private Session          session     = null;

   @Override
   public void process(List<RoutableModuleData> routableProcessObjects) 
   throws OndotException
   {
    try
    {
        session = sessionFactory.openSession();
        session.flush();
            canonicalMessage = 
       lookupprocesser.processInput(canonicalMessage, 
       Constants.L1_LOOKUP_CACHE, session);
    }
    catch (Exception Ex)
    {
    }
    finally
    {
        if (session != null && session.isOpen()){
            session.close();
        }
    }
    }
    }

    public class Lookupprocesser{
     public CanonicalMessage processInput(CanonicalMessage canonicalMessage, 
     String cacheLookup, Session session) throws DataInsightsCommonException
      {
         lookupSearchForL1(canonicalMessage, session, cacheLookup);
          return canonicalMessage;
       }
    }

     public class Query{

      public List<TerminalData> searchByMatchKey1AndMatchKey2(Session 
      session, String matchKey1, String matchKey2) throws 
      DataInsightsCommonException
         {
         Query query;
         List<Data> t = null;
           query = session.createQuery("from Data as odt where odt.Key1 is 
           null and odt.Key2 = :Key2");
           query.setParameter(Constants.KEY2, Key2);
           query.setCacheable(true);
          terminals = (List<Data>) query.list();
             return (null != t && !t.isEmpty()) ? t : null;
      }
     }