Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
sentinel
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
sentinel
Commits
28c94434
Commit
28c94434
authored
Jul 29, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
01c22ae6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
5 deletions
+35
-5
SqlConcurrentController.java
.../java/com/egolm/sentinel/web/SqlConcurrentController.java
+32
-5
sqlConcurrent.html
src/main/resources/page/sqlConcurrent.html
+3
-0
No files found.
src/main/java/com/egolm/sentinel/web/SqlConcurrentController.java
View file @
28c94434
...
...
@@ -17,6 +17,10 @@ import org.springframework.dao.DataAccessException;
import
org.springframework.jdbc.core.CallableStatementCallback
;
import
org.springframework.jdbc.core.CallableStatementCreator
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
org.springframework.transaction.TransactionStatus
;
import
org.springframework.transaction.support.TransactionCallback
;
import
org.springframework.transaction.support.TransactionTemplate
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -30,16 +34,25 @@ import com.egolm.sentinel.config.XRException;
public
class
SqlConcurrentController
{
@PostMapping
(
"concurrentSql"
)
public
Rjx
doExecute
(
String
jdbcUrl
,
String
username
,
String
password
,
String
sql
,
String
parameters
,
int
threadCount
,
int
executeCount
)
throws
InterruptedException
,
IOException
,
SQLException
{
public
Rjx
doExecute
(
String
jdbcUrl
,
String
username
,
String
password
,
String
sql
,
String
parameters
,
Integer
threadCount
,
Integer
executeCount
,
Integer
isOpenTx
)
throws
InterruptedException
,
IOException
,
SQLException
{
threadCount
=
threadCount
==
null
?
1
:
threadCount
;
executeCount
=
executeCount
==
null
?
1
:
executeCount
;
isOpenTx
=
isOpenTx
==
null
?
0
:
isOpenTx
;
ThreadPoolExecutor
executor
=
new
ThreadPoolExecutor
(
threadCount
,
threadCount
,
5
,
TimeUnit
.
MINUTES
,
new
LinkedBlockingQueue
<
Runnable
>(
executeCount
));
CountDownLatch
latch
=
new
CountDownLatch
(
executeCount
);
DruidDataSource
dataSource
=
null
;
Long
start
=
System
.
currentTimeMillis
();
try
{
dataSource
=
this
.
getDataSource
(
jdbcUrl
,
username
,
password
);
TransactionTemplate
txTemplate
=
null
;
if
(
isOpenTx
.
intValue
()
==
1
)
{
DataSourceTransactionManager
txManager
=
new
DataSourceTransactionManager
(
dataSource
);
txTemplate
=
new
TransactionTemplate
(
txManager
);
}
JdbcTemplate
jdbcTemplate
=
new
JdbcTemplate
(
dataSource
);
for
(
int
i
=
0
;
i
<
executeCount
;
i
++)
{
executor
.
execute
(
new
Runner
(
jdbcTemplate
,
latch
,
sql
));
executor
.
execute
(
new
Runner
(
jdbcTemplate
,
txTemplate
,
latch
,
sql
));
}
latch
.
await
();
}
finally
{
...
...
@@ -51,13 +64,15 @@ public class SqlConcurrentController {
public
static
class
Runner
implements
Runnable
{
JdbcTemplate
jdbcTemplate
;
private
TransactionTemplate
txTemplate
;
private
JdbcTemplate
jdbcTemplate
;
private
CountDownLatch
latch
;
private
String
sql
;
private
String
parameters
;
public
Runner
(
JdbcTemplate
jdbcTemplate
,
CountDownLatch
latch
,
String
sql
)
{
public
Runner
(
JdbcTemplate
jdbcTemplate
,
TransactionTemplate
txTemplate
,
CountDownLatch
latch
,
String
sql
)
{
super
();
this
.
txTemplate
=
txTemplate
;
this
.
jdbcTemplate
=
jdbcTemplate
;
this
.
latch
=
latch
;
this
.
sql
=
sql
;
...
...
@@ -65,6 +80,18 @@ public class SqlConcurrentController {
@Override
public
void
run
()
{
if
(
txTemplate
!=
null
)
{
txTemplate
.
execute
(
new
TransactionCallback
<
List
<
Object
>>()
{
public
List
<
Object
>
doInTransaction
(
TransactionStatus
status
)
{
return
executeSql
();
}
});
}
else
{
executeSql
();
}
}
public
List
<
Object
>
executeSql
()
{
try
{
List
<
Object
>
argList
=
new
ArrayList
<
Object
>();
if
(
StringUtil
.
isNotBlank
(
parameters
))
{
...
...
@@ -86,7 +113,7 @@ public class SqlConcurrentController {
}
Object
[]
args
=
argList
.
toArray
(
new
Object
[
argList
.
size
()]);
jdbcTemplate
.
execute
(
new
CallableStatementCreator
()
{
return
jdbcTemplate
.
execute
(
new
CallableStatementCreator
()
{
public
CallableStatement
createCallableStatement
(
final
Connection
con
)
throws
SQLException
{
final
CallableStatement
cs
=
con
.
prepareCall
(
sql
);
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
...
...
src/main/resources/page/sqlConcurrent.html
View file @
28c94434
...
...
@@ -34,6 +34,9 @@
<el-form-item>
<el-input
size=
"mini"
placeholder=
"参数"
v-model=
"form.parameters"
style=
"width:300px;"
></el-input>
</el-form-item>
<el-form-item>
<el-input
size=
"mini"
placeholder=
"参数"
v-model=
"form.parameters"
style=
"width:300px;"
></el-input>
</el-form-item>
<el-form-item>
<el-button
size=
"mini"
type=
"primary"
@
click=
"doExecute"
>
执行
</el-button>
</el-form-item>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment