Glassfish RAR5035:从池中销毁资源时出现意外异常

时间:2016-05-27 12:23:46

标签: jdbc glassfish ejb connection-pooling ejb-3.1

我有一个Java EE Web应用程序。我正在使用JDBC连接数据库,我正在使用JDBC连接池。我的应用程序的主页面是登录页面。在我进入登录页面并等待一段时间后,我会一直采用此glassfish服务器(4.1.0)警告。

  

警告:RAR5035:从中销毁资源时发生意外异常   池OraclePool。异常消息:销毁资源时出错   :IO错误:套接字读取超时

即使我没有在页面上执行任何操作。当我监视连接池的统计信息时,@ManagedBean @SessionScoped public class Login implements Serializable{ private String userName; private String password; private User user; private @EJB DBRemote db; public void test(){ String[] params1 = {"user","1234"}; int[] getParams = {Types.INTEGER,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR}; CallableStatement statement = db.run("TBL.USERLOGIN(?,?,?,?,?,?)", params1 , getParams); try { int isLogin = statement.getInt(3); if (isLogin==1) { String uName = statement.getString(4); String uId = statement.getString(5); user = new User(uId, uName, isLogin); System.out.println("LOGGED IN " + uName + "\t" + uId); }else{ String errMessage = statement.getString(6); user = new User(errMessage,isLogin); System.out.println("LOG IN FAILURE " + errMessage); } } catch (SQLException ex) { Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex); }finally{ db.close(); FacesContext.getCurrentInstance().addMessage("infoback", new FacesMessage(FacesMessage.SEVERITY_INFO, "TEST","Test Works")); } } } 会不断增加。我该如何解决这个问题?谢谢。

pool_statistics_image

这是我的托管bean类。

@Remote
public interface DBRemote {
    CallableStatement run(String query, String[] setParams, int[] getParams);
    void close();
    String getErrorMessage();
    String getSql();
}

这是我的界面类

@Stateless
public class DB implements DBRemote{

    @Resource(mappedName = "pwresource")
    private DataSource ds;

    private String sql;
    private String errorMessage;
    private CallableStatement statement;
    private Connection connection;

    public DB() {
    }

    @Override
    public CallableStatement run(String query, String[] setParams, int[] getParams){
        sql = "{call " + query + "}";
        int getParamIndex = setParams.length + 1;
        try {
            connection = ds.getConnection();
            statement = connection.prepareCall(sql);
            for (int i = 0; i < setParams.length; i++) {
                statement.setString(i+1, setParams[i]);
            }
            for (int getParam : getParams) {
                statement.registerOutParameter(getParamIndex, getParam);
                getParamIndex++;
            }
           statement.execute();

        }catch (SQLException ex) {
            if (ex.getErrorCode()==17008) {
                errorMessage = "Timeout";
            }else{
                errorMessage = "System Error";
            }
            Logger.getLogger(DB.class.getName()).log(Level.SEVERE, null, ex);
            close();
        }
        return statement;
    }

    @Override
    public void close(){
        try {
            if (statement != null) {
                statement.close();
            }
            if(connection != null){
                connection.close();
            }
        errorMessage = null;
        } catch (SQLException e) {
            errorMessage = "Close Connection Error";
        }
    }

    @Override
    public String getErrorMessage() {
        return errorMessage;
    }

    @Override
    public String getSql() {
        return sql;
    }


}

这是我的无状态Bean类

 #menu-item-207 .menu-image-title,
 #menu-item-206 .menu-image-title,
 #menu-item-205 .menu-image-title,
 #menu-item-204 .menu-image-title,
 #menu-item-203 .menu-image-title,
 #menu-item-202 .menu-image-title,
 #menu-item-201 .menu-image-title,
 #menu-item-200 .menu-image-title {
    color: black !important; 
 }  
 #menu-item-207 .menu-image-title:hover,
 #menu-item-206 .menu-image-title:hover,
 #menu-item-205 .menu-image-title:hover,
 #menu-item-204 .menu-image-title:hover,
 #menu-item-203 .menu-image-title:hover,
 #menu-item-202 .menu-image-title:hover,
 #menu-item-201 .menu-image-title:hover,
 #menu-item-200 .menu-image-title:hover {
     color: #0095d1 !important; 
 }

1 个答案:

答案 0 :(得分:0)

我已经解决了我的问题。我的问题是因为连接池和数据库之间的连接。数据库自动关闭连接,因为不同网络中的服务器和数据库导致超时问题。