hibernate - हाइबरनेट सी 3 पी 0 कनेक्शन न्यूपूलड कनेक्शन कनेक्शन अपवाद



jboss c3p0 (1)

मैं अपनी पिछली पोस्ट java.sql.SQLRecoverableException से अपनी समस्या हल करने की कोशिश कर रहा था : बंद कनेक्शन मैं c3p0 कनेक्शन के साथ कोशिश की। संपत्ति निम्नानुसार है,

<property name="hibernate.connection.provider_class">
        org.hibernate.connection.C3P0ConnectionProvider</property>
    <property name="hibernate.connection.autoReconnect">true</property>
    <property name="dialect"> org.hibernate.dialect.Oracle10gDialect </property>
    <property name="hibernate.c3p0.min_size">5</property>
    <property name="hibernate.c3p0.max_size">20</property>
    <property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.idle_test_period">6000</property>
    <property name="hibernate.c3p0.numHelperThreads">9</property>

JBOSS में तैनात करने के बाद मैंने अपनी वेब का परीक्षण करना शुरू कर दिया। शुरुआत में यह ठीक और भी तेजी से काम कर रहा था। 10 मिनट के बाद यह लोड हो रहा था और समय समाप्त हो गया था। जब server.log के माध्यम से चले गए तो मुझे कुछ चेतावनी संदेश मिले, जैसे निम्नानुसार।

00:34:13,162 INFO  [com.mchange.v2.c3p0.impl.NewPooledConnection] com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2) [c3p0] Exceptions occurred while trying to close a PooledConnection's resources normally.
00:34:13,162 INFO  [com.mchange.v2.c3p0.impl.NewPooledConnection] (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2) [c3p0] NewPooledConnection close Exception.: java.sql.SQLRecoverableException: IO Error: Software  caused connection abort: recv failed
at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:556)   [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.PhysicalConnection.close(PhysicalConnection.java:3984) [ojdbc6.jar:11.2.0.3.0]
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:474) [c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:191) [c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470) [c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964) [c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547) [c3p0-0.9.1.jar:0.9.1]
Caused by: java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method) [rt.jar:1.6.0_13]
at java.net.SocketInputStream.read(SocketInputStream.java:129) [rt.jar:1.6.0_13]
at oracle.net.ns.Packet.receive(Packet.java:300) [ojdbc6.jar:11.2.0.3.0]
at oracle.net.ns.DataPacket.receive(DataPacket.java:106) [ojdbc6.jar:11.2.0.3.0]
at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:315) [ojdbc6.jar:11.2.0.3.0]
at oracle.net.ns.NetInputStream.read(NetInputStream.java:260) [ojdbc6.jar:11.2.0.3.0]
at oracle.net.ns.NetInputStream.read(NetInputStream.java:185) [ojdbc6.jar:11.2.0.3.0]
at oracle.net.ns.NetInputStream.read(NetInputStream.java:102) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:124) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:80) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1137) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:290) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4C7Ocommoncall.doOLOGOFF(T4C7Ocommoncall.java:61) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:543) [ojdbc6.jar:11.2.0.3.0]
... 6 more

00:34:13,177 WARN  [com.mchange.v2.resourcepool.BasicResourcePool] (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2) Failed to destroy resource: [email protected]: java.sql.SQLException: Some resources failed to close properly while closing [email protected]
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:496) [c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:191) [c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470) [c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964) [c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547) [c3p0-0.9.1.jar:0.9.1]

कृपया इस मुद्दे को हल करने के लिए कुछ सुझाव दें।


यह समस्या कुछ समय में उठती है जब सत्र बंद हो जाता है और सत्र के लिए इस्तेमाल कनेक्शन अभी भी जीवित है, और एक नया सत्र खोलने पर एक नया सत्र खोला जाता है। यह कनेक्शन पूल में निर्दिष्ट कनेक्शन के अधिक उपयोग के लिए होता है, और सहायक थ्रेड्स उनके भाग निभाते हैं और मेरी समस्या यहां आती है। मैंने अपना हाइबरनेट सत्र फेक्टर वर्ग बदल दिया और स्वनिर्धारित कनेक्शन प्रदाता ने मेरी समस्या हल की। परिवर्तन इस प्रकार हैं ...

public class HibernateSessionFactory {
private staticString CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
private static Configuration configuration = new Configuration();
private static org.hibernate.SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION;
public static Session session;
static {
    try {
        configuration.configure(configFile);
        sessionFactory = configuration.buildSessionFactory();
    } catch (Exception e) {
        System.err.println("%%%% Error Creating SessionFactory %%%%");
        e.printStackTrace();
    }
}

public HibernateSessionFactory() {
}
public static Session getSession() throws HibernateException {

    try {
        if (session == null) {
            session = sessionFactory.openSession(MyConnectionProvider
                    .getConn());
        } else {

            if (session.isOpen() && !session.connection().isClosed()) {

                System.out.println("SESSION AVAILABLE...");

                MyConnectionProvider.showConnectionDetails();

                return session;
            }

            if (!session.isOpen()) {
                System.out.println("SESSION WAS CLOSED AND OPEN AGAIN..");
                session = sessionFactory.openSession(MyConnectionProvider
                        .getConn());
            } else if (session.connection().isClosed()) {

                System.out.println("CONNECTION WAS CLOSED AND OPENING AGAIN...");

                session.close();

                session = sessionFactory.openSession(MyConnectionProvider
                        .getConn());
            }

        }
        MyConnectionProvider.showConnectionDetails();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return session;
}
public static org.hibernate.SessionFactory getSessionFactory() {
    return sessionFactory;
}
public static void setConfigFile(String configFile) {
    HibernateSessionFactory.configFile = configFile;
    sessionFactory = null;
}
public static Configuration getConfiguration() {
    return configuration;
}

}

MyConnectionProvider वर्ग को एंज है

public class MyConnectionProvider {

static String jdbcDriverClass;
static String jdbcUrl;
static String username;
static String password;
static String poolSize = "20";

static ComboPooledDataSource ds;

static {

    config(HibernateSessionFactory.getConfiguration().getProperties());

    ds = new ComboPooledDataSource();

    // System.out.println(" "+jdbcUrl);

    ds.setJdbcUrl(jdbcUrl);

    // System.out.println(username);

    ds.setUser(username);

    // System.out.println(password);

    ds.setPassword(password);

    ds.setMinPoolSize(1);

    ds.setMaxPoolSize(20);

}

public static void config(Properties props) {

    System.out.println("SETTING CONFIGURATION...");

    jdbcDriverClass = props.getProperty(Environment.DRIVER);
    jdbcUrl = props.getProperty(Environment.URL);
    username = props.getProperty(Environment.USER);
    password = props.getProperty(Environment.PASS);

    System.out.println(jdbcDriverClass + "  " + jdbcUrl + "  " + username
            + "  " + password + "  " + poolSize);
}

public static Connection getConn() {
    Connection conn = null;
    try {
        System.out.println("URL " + ds.getJdbcUrl());
        System.out.println("Busy Connections : "
                + ds.getNumBusyConnections("user", "user"));
        return ds.getConnection();
    } catch (SQLException e) {

        // TODO Auto-generated catch block
        e.printStackTrace();
        return conn;
    }
}

public static void showConnectionDetails() {

    try {
        System.out.println("Busy Connections :  "
                + ds.getNumBusyConnections() + " Connections : "
                + ds.getNumConnections() + " Thread Pool Size : "
                + ds.getThreadPoolSize() + " Active Threads : "
                + ds.getThreadPoolNumActiveThreads() + "  Idle Threads : "
                + ds.getThreadPoolNumIdleThreads() + "  Pending Tasks : "
                + ds.getThreadPoolNumTasksPending());
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}




c3p0