问题:我收到以下错误
我想在tomcat中配置线程和连接池,以便在最佳级别使用它们。 我可以配置高达500-600线程的吞吐量, 我有更多的servlet将使用具有类似线程的数据库。
我正在调用一个servlet来插入db(下面提到的代码)中的条目,其中包含150个Threads,要完成的任务是100000
static int joblimit = 100000;
static int TPS = 150;
public static void insertMethod()
{
RateLimiter rateLimiter = RateLimiter.create(TPS);
ExecutorService executorService = Executors.newCachedThreadPool();
start = System.currentTimeMillis();
for (int i = 0; i < joblimit; i++) {
rateLimiter.acquire(); // may wait
final int j = i;
executorService.execute(new Runnable() {
@Override
public void run() {
log.info(str);
try {
callInsertURL(j);
} catch (Exception e) {
log.error(e);
}
if (index == joblimit) {
long timeTaken = System.currentTimeMillis() - start;
String oneThreadProcessedInSecs = ""+(float)(1*(timeTaken/60)/joblimit);
log.info(joblimit + " jobs completed in "
+ timeTaken
+ " msec i.e ["+(float)(timeTaken/60)+"sec,"+"] with " + TPS + " tps, oneThreadProcessedInSecs="+oneThreadProcessedInSecs);
}
}
});
}
try {
executorService.shutdown();
executorService.awaitTermination(100, TimeUnit.SECONDS);
log.info("--------------All Tasks Processed Processed----------------------------");
} catch (Exception e) {
e.printStackTrace();
}
}
我的Tomcat和Java配置: Context.xml条目
<Resource name="jdbc/myoracle"
global="jdbc/myoracle"
auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@myip:1521:mydb"
username="myusername" password="mypassword" maxActive="250" maxIdle="30" maxWait="10000"
/>
server.xml条目
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
Spring配置:servlet-context.xml
<beans:bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<beans:property name="jndiName" value="java:comp/env/jdbc/myoracle"/>
</beans:bean>
ServeltController将调用以下方法插入DB:
@Autowired
@Qualifier("commonDAO")
protected CommonDAO commonDAO;
String qry = "INSERT INTO TB_CUSTOMER(customer_msisdn,op_id,cuser,country_id) VALUES(?,?,?,?)";
String[] colNamesTobeReturned = {"CUSTOMER_ID"};
commonDAO.insertOrUpdateWithReturnPK(qry, colNamesTobeReturned, msisdn,opid,cuser,countryid);
将访问数据库的方法:
public Long insertOrUpdateWithReturnPK(final String qry,final String[] colNamesTobeReturned,final Object... params)
{
KeyHolder keyHolder = new GeneratedKeyHolder();
try {
getJdbcTemplate().update(
new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement(qry, colNamesTobeReturned);
utilMapParamsToPStmt(ps,params);
return ps;
}
},
keyHolder);
if(keyHolder != null)
return keyHolder.getKey().longValue();
} catch (Exception e) {
handleDBExceptions(e);
}
return 0L;
}