Commit bce81833 authored by Quxl's avatar Quxl

x

parent 5a4412f3
......@@ -33,8 +33,10 @@ import com.egolm.sentinel.config.XRException;
@RestController
public class SqlConcurrentController {
@PostMapping("concurrentSql")
public Rjx doExecute(String jdbcUrl, String username, String password, String sql, String parameters, Integer threadCount, Integer executeCount, Boolean isOpenTx) throws InterruptedException, IOException, SQLException {
List<Object> list = new ArrayList<Object>();
threadCount = threadCount == null ? 1 : threadCount;
executeCount = executeCount == null ? 1 : executeCount;
isOpenTx = isOpenTx == null ? false : isOpenTx;
......@@ -52,43 +54,47 @@ public class SqlConcurrentController {
}
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
for(int i = 0; i < executeCount; i++) {
executor.execute(new Runner(jdbcTemplate, txTemplate, latch, sql));
executor.execute(new Runner(jdbcTemplate, txTemplate, latch, sql, list));
}
latch.await();
} finally {
dataSource.close();
}
Long end = System.currentTimeMillis();
return Rjx.jsonOk().set("执行时间", (end-start)).set("执行次数", executeCount).set("并发线程", threadCount);
return Rjx.jsonOk().setData(list).set("执行时间", (end-start)).set("执行次数", executeCount).set("并发线程", threadCount);
}
public static class Runner implements Runnable {
private List<Object> list;
private TransactionTemplate txTemplate;
private JdbcTemplate jdbcTemplate;
private CountDownLatch latch;
private String sql;
private String parameters;
public Runner(JdbcTemplate jdbcTemplate, TransactionTemplate txTemplate, CountDownLatch latch, String sql) {
public Runner(JdbcTemplate jdbcTemplate, TransactionTemplate txTemplate, CountDownLatch latch, String sql, List<Object> list) {
super();
this.txTemplate = txTemplate;
this.jdbcTemplate = jdbcTemplate;
this.latch = latch;
this.sql = sql;
this.list = list;
}
@Override
public void run() {
List<Object> result;
if(txTemplate != null) {
txTemplate.execute(new TransactionCallback<List<Object>>() {
result = txTemplate.execute(new TransactionCallback<List<Object>>() {
public List<Object> doInTransaction(TransactionStatus status) {
return executeSql();
}
});
} else {
executeSql();
result = executeSql();
}
list.add(result);
}
public List<Object> executeSql() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment