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

Glassfish RAR5035:Unexpected Exception While Destroying Resource From Pool

我有一个 Java EE 网络应用程序。我正在使用 JDBC 连接数据库,并且正在使用 JDBC 连接池。我的应用程序的主页是登录页面。进入登录页面等待一段时间后,我一直收到这个glassfish server(4.1.0)警告。

Warning: RAR5035:Unexpected exception while destroying resource from pool OraclePool. Exception message: Error while destroying resource :IO Error: Socket read timed out

即使我没有在页面上执行任何操作。当我监视连接池的统计数据时,NumConnCreated 不断增加。我该如何解决这个问题?谢谢。

这是我的托管 bean class。

@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"));
        }
    }

}

这是我的界面class

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

这是我的无状态 Bean class

@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;
    }


}

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