package cn.com;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.opensymphony.xwork2.ActionSupport;
import tool.DBConnect;
public class TestThread extends ActionSupport
{
private int accessMethod = 0;
private int count = 0;
private int threadNum = 0;
private double span = 0.0000;
private static String sqlBound = "insert into TestBound (id) values(?)";
class RunThread implements Runnable
{
public void run()
{
try
{
Connection connection = DBConnect.getCon();
Random rand = new Random(545);
if (accessMethod == 1)
{
PreparedStatement prepare = connection.prepareStatement(sqlBound);
for (int i = 0; i < count; i++)
{
prepare.setInt(1, rand.nextInt(100000));
prepare.executeUpdate();
}
prepare.close();
}
else if (accessMethod == 2)
{
Statement stat = connection.createStatement();
for (int i = 0; i < count; i++)
{
stat.executeUpdate("insert into TestBound (id) values(" + rand.nextInt(100000) + ")");
}
stat.close();
}
connection.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public String execute()
{
try
{
long time = System.nanoTime();
ExecutorService exec = Executors.newFixedThreadPool(threadNum);
for (int i = 0; i < threadNum; i++)
{
exec.execute(new RunThread());
}
exec.shutdown();
while (!exec.isTerminated())
{
Thread.sleep(500);
}
time = System.nanoTime() - time;
span = (double) time / 1000000000;
}
catch (Exception e)
{
e.printStackTrace();
}
return SUCCESS;
}
public int getAccessMethod()
{
return accessMethod;
}
public void setAccessMethod(int accessMethod)
{
this.accessMethod = accessMethod;
}
public int getCount()
{
return count;
}
public void setCount(int count)
{
this.count = count;
}
public int getThreadNum()
{
return threadNum;
}
public void setThreadNum(int threadNum)
{
this.threadNum = threadNum;
}
public double getSpan()
{
return span;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
一个简单基于struts2实现的数据库查询
共57个文件
jar:19个
xml:9个
class:9个
5星 · 超过95%的资源 需积分: 50 203 下载量 66 浏览量
2009-05-24
18:07:20
上传
评论 3
收藏 7.33MB RAR 举报
温馨提示
一个简单基于struts2实现的数据库查询,利用缓存池,并且只需移动db.xml文件就可以访问不同数据库
资源推荐
资源详情
资源评论
收起资源包目录
mytest2.rar (57个子文件)
mytest2
.project 1KB
WEB-INF
classes
cn
com
db.xml 401B
.settings
.jsdtscope 406B
org.eclipse.jdt.core.prefs 330B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
.mymetadata 294B
WebRoot
WEB-INF
web.xml 764B
lib
commons-chain-1.2.jar 90KB
commons-dbcp.jar 119KB
freemarker-2.3.13.jar 850KB
commons-collections-3.2.jar 558KB
sqljdbc.jar 227KB
ognl-2.6.11.jar 164KB
commons-logging-1.0.4.jar 37KB
xwork-2.1.2.jar 2.18MB
commons-digester-1.8.jar 140KB
commons-logging-api-1.1.jar 44KB
commons-beanutils-1.7.0.jar 184KB
struts2-core-2.1.6.jar 719KB
commons-fileupload-1.2.1.jar 56KB
commons-lang-2.3.jar 240KB
ojdbc6.jar 1.89MB
commons-pool.jar 61KB
antlr-2.7.2.jar 350KB
commons-validator-1.3.1.jar 136KB
commons-io-1.3.2.jar 86KB
classes
cn
com
dao
RunSQL.class 899B
ColNameMap.class 1KB
TestThread$RunThread.class 2KB
TestThread.class 2KB
Start.class 3KB
db.xml 401B
Column.class 2KB
TestBound.class 2KB
tool
ReadXML.class 3KB
DBConnect.class 1KB
struts.xml 894B
index.jsp 1KB
META-INF
MANIFEST.MF 39B
db.xml 429B
jsp
testThread.jsp 581B
db.xml 429B
testBound.jsp 499B
default.jsp 986B
db.xml 429B
.myeclipse
src
cn
com
Column.java 1KB
dao
ColNameMap.java 1021B
RunSQL.java 601B
TestThread.java 2KB
db.xml 401B
TestBound.java 2KB
Start.java 2KB
tool
ReadXML.java 2KB
DBConnect.java 1KB
struts.xml 894B
.classpath 1KB
共 57 条
- 1
yangfan198483
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页