我正在开始研究一个位于Oracle 10g上的小型Java Web应用程序.预期的用户群最多可达100个用户.我不希望使用该应用程序一次看到超过50个用户.
现在,我正在考虑DBCP,C3P0或Tomcat JDBC连接池,但是这会为这么小的用户群增加真正的价值吗?我从来没有使用任何解决方案,所以存在引入复杂性的风险(我已经看到其他线程,人们面临着连接池的一些疯狂问题)而且我不确定这些好处会超过风险.或者还有其他方法吗?也许Oracle拥有自己的解决方案?
请帮忙.
谢谢.
我的services.xml中有以下代码
<bean id="executorService" class="java.util.concurrent.Executors" factory-method="newFixedThreadPool">
<constructor-arg value="10" />
</bean>
<task:annotation-driven executor="executor" />
<task:executor id="executor" pool-size="10" queue-capacity="100" rejection-policy="CALLER_RUNS" />
Run Code Online (Sandbox Code Playgroud)
在同一项目中,我还具有使用dbcp.BasicDataSource的数据库连接。
我已经读到DBCP在您的应用程序是单线程而不是多线程时才有效。使用executor告诉我该应用程序是多线程的。您认为在这里使用DBCP是否不合适?这是一个好习惯吗?或者,我是否有一个古老的神话,那就是DBCP无法处理多种环境?
朝着正确方向的任何指导将不胜感激。
java spring multithreading executorservice apache-commons-dbcp
I have made a Java webapp with Spring, Hibernate and MySQL. It runs correctly, but in the first attempt to connect, I have the following error:
HTTP Status 500 - Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin failed:
type Exception report
message Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin failed:
description The server encountered …Run Code Online (Sandbox Code Playgroud) 我得到了这个 Java Web 应用程序,它恰好与 SQL Server 数据库进行了过多的通信。我想决定如何以有效的方式管理与该数据库的连接。我想到的第一个选项是使用第三方连接池。我选择了C3P0和DBCP,并准备了一些测试用例来比较这些方法,如下所示:
无池化:
public static void main(String[] args) {
long startTime=System.currentTimeMillis();
try {
for (int i = 0; i < 100; i++) {
Connection conn = ConnectionManager_SQL.getInstance().getConnection();
String query = "SELECT * FROM MyTable;";
PreparedStatement prest = conn.prepareStatement(query);
ResultSet rs = prest.executeQuery();
if (rs.next()) {
System.out.println(i + ": " + rs.getString("CorpName"));
}
conn.close();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Finished in: "+(System.currentTimeMillis()-startTime)+" milli secs");
}
Run Code Online (Sandbox Code Playgroud)
二氯苯酚:
public static …Run Code Online (Sandbox Code Playgroud)