Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database 在weblogic集群环境中,单例数据库连接会影响性能吗?_Database_Jakarta Ee_Struts_Weblogic_Cluster Computing - Fatal编程技术网

Database 在weblogic集群环境中,单例数据库连接会影响性能吗?

Database 在weblogic集群环境中,单例数据库连接会影响性能吗?,database,jakarta-ee,struts,weblogic,cluster-computing,Database,Jakarta Ee,Struts,Weblogic,Cluster Computing,我有一个使用单例数据库连接的JavaEEStrutsWeb应用程序。过去,只有一台weblogic服务器,但现在,集群中有两台weblogic服务器 会话复制已测试在此群集中正常工作。web应用程序由几个链接组成,这些链接将打开不同的表单供用户填写。每个表单都有一个动态下拉列表,该列表将根据单击的表单填充一些值。这些dropdownlist值是从oracle数据库中检索的 一个独特的问题是,单击的第一个表单可能需要2-5秒,而单击的第二个表单可能需要很长时间才能加载或超过5分钟。我检查了代码,碰

我有一个使用单例数据库连接的JavaEEStrutsWeb应用程序。过去,只有一台weblogic服务器,但现在,集群中有两台weblogic服务器

会话复制已测试在此群集中正常工作。web应用程序由几个链接组成,这些链接将打开不同的表单供用户填写。每个表单都有一个动态下拉列表,该列表将根据单击的表单填充一些值。这些dropdownlist值是从oracle数据库中检索的

一个独特的问题是,单击的第一个表单可能需要2-5秒,而单击的第二个表单可能需要很长时间才能加载或超过5分钟。我检查了代码,碰巧知道问题出在试图调用db连接的一个实例时。这会是僵局吗

public static synchronized DataSingleton getDataSingleton()
throws ApplicationException {
        if (myDataSingleton == null) {
            myDataSingleton = new DataSingleton();
        }
        return myDataSingleton;
    }
如果您能帮助解释这种情况,我们将不胜感激

多谢各位

A sample read operation calling Singleton 

String sql = "...";
DataSingleton myDataSingleton = DataSingleton.getDataSingleton();
conn = myDataSingleton.getConnection();

        try {

            PreparedStatement pstmt = conn.prepareStatement(sql);

            try {
                pstmt.setString(1, userId);
                ResultSet rs = pstmt.executeQuery();

                try {
                    while (rs.next()) {
                        String group = rs.getString("mygroup");
                    }

                } catch (SQLException rsEx) {
                    throw rsEx;

                } finally {
                    rs.close();
                }
            } catch (SQLException psEx) {
                throw psEx;

            } finally {
                pstmt.close();
            }
        } catch (SQLException connEx) {
            throw connEx;

        } finally {
            conn.close();
        }



 The Singleton class
 /**
 * Private Constructor looking up for Server's Datasource through JNDI
 */
private DataSingleton() throws ApplicationException {
    try {
        Context ctx = new InitialContext();
        SystemConstant mySystemConstant = SystemConstant
                .getSystemConstant();

        String fullJndiPath = mySystemConstant.getFullJndiPath();
        ds = (DataSource) ctx.lookup(fullJndiPath);

    } catch (NamingException ne) {
        throw new ApplicationException(ne);
    }
}

/**
 * Singleton: To obtain only 1 instance throughout the system
 * 
 * @return DataSingleton
 */
public static synchronized DataSingleton getDataSingleton()
        throws ApplicationException {
    if (myDataSingleton == null) {
        myDataSingleton = new DataSingleton();
    }

    return myDataSingleton;
}

/**
 * Fetching SQL Connection through Datasource
 * 
 */
public Connection getConnection() throws ApplicationException {
    Connection conn = null;
    try {

        if (ds == null) {
        }

        conn = ds.getConnection();

      } catch (SQLException sqlE) {
        throw new ApplicationException(sqlE);
    }
    return conn;
}

听起来您可能没有在使用连接结束时提交事务


DataSingleton中有什么-是数据库连接吗?允许多个线程访问同一个数据库连接是行不通的,例如,当您有多个用户时。为什么不使用数据库连接池,例如数据源?

是的,它只包含创建数据库连接ds=(数据源)ctx.lookup(jndiPath);我是否必须为“读取”操作执行“提交”操作?您是否调用类似dataSingleton.getConnection()的东西,还是缓存单个连接然后共享?每次有读取操作时,我都会调用dataSingleton myDataSingleton=dataSingleton.getDataSingleton();conn=myDataSingleton.getConnection();可能值得发布DataSingleton代码——从您的评论来看,它可能是一个共享连接,这将在多用户环境中导致问题。关于您发布的问题,您是否在使用conn结束时提交事务?也许会发布代码来展示如何使用它。我没有在代码级别处理任何提交事务。有必要吗?