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
bce81833
Commit
bce81833
authored
Jul 29, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
5a4412f3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
5 deletions
+11
-5
SqlConcurrentController.java
.../java/com/egolm/sentinel/web/SqlConcurrentController.java
+11
-5
No files found.
src/main/java/com/egolm/sentinel/web/SqlConcurrentController.java
View file @
bce81833
...
@@ -33,8 +33,10 @@ import com.egolm.sentinel.config.XRException;
...
@@ -33,8 +33,10 @@ import com.egolm.sentinel.config.XRException;
@RestController
@RestController
public
class
SqlConcurrentController
{
public
class
SqlConcurrentController
{
@PostMapping
(
"concurrentSql"
)
@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
{
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
;
threadCount
=
threadCount
==
null
?
1
:
threadCount
;
executeCount
=
executeCount
==
null
?
1
:
executeCount
;
executeCount
=
executeCount
==
null
?
1
:
executeCount
;
isOpenTx
=
isOpenTx
==
null
?
false
:
isOpenTx
;
isOpenTx
=
isOpenTx
==
null
?
false
:
isOpenTx
;
...
@@ -52,43 +54,47 @@ public class SqlConcurrentController {
...
@@ -52,43 +54,47 @@ public class SqlConcurrentController {
}
}
JdbcTemplate
jdbcTemplate
=
new
JdbcTemplate
(
dataSource
);
JdbcTemplate
jdbcTemplate
=
new
JdbcTemplate
(
dataSource
);
for
(
int
i
=
0
;
i
<
executeCount
;
i
++)
{
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
();
latch
.
await
();
}
finally
{
}
finally
{
dataSource
.
close
();
dataSource
.
close
();
}
}
Long
end
=
System
.
currentTimeMillis
();
Long
end
=
System
.
currentTimeMillis
();
return
Rjx
.
jsonOk
().
set
(
"执行时间"
,
(
end
-
start
)).
set
(
"执行次数"
,
executeCount
).
set
(
"并发线程"
,
threadCount
);
return
Rjx
.
jsonOk
().
set
Data
(
list
).
set
(
"执行时间"
,
(
end
-
start
)).
set
(
"执行次数"
,
executeCount
).
set
(
"并发线程"
,
threadCount
);
}
}
public
static
class
Runner
implements
Runnable
{
public
static
class
Runner
implements
Runnable
{
private
List
<
Object
>
list
;
private
TransactionTemplate
txTemplate
;
private
TransactionTemplate
txTemplate
;
private
JdbcTemplate
jdbcTemplate
;
private
JdbcTemplate
jdbcTemplate
;
private
CountDownLatch
latch
;
private
CountDownLatch
latch
;
private
String
sql
;
private
String
sql
;
private
String
parameters
;
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
();
super
();
this
.
txTemplate
=
txTemplate
;
this
.
txTemplate
=
txTemplate
;
this
.
jdbcTemplate
=
jdbcTemplate
;
this
.
jdbcTemplate
=
jdbcTemplate
;
this
.
latch
=
latch
;
this
.
latch
=
latch
;
this
.
sql
=
sql
;
this
.
sql
=
sql
;
this
.
list
=
list
;
}
}
@Override
@Override
public
void
run
()
{
public
void
run
()
{
List
<
Object
>
result
;
if
(
txTemplate
!=
null
)
{
if
(
txTemplate
!=
null
)
{
txTemplate
.
execute
(
new
TransactionCallback
<
List
<
Object
>>()
{
result
=
txTemplate
.
execute
(
new
TransactionCallback
<
List
<
Object
>>()
{
public
List
<
Object
>
doInTransaction
(
TransactionStatus
status
)
{
public
List
<
Object
>
doInTransaction
(
TransactionStatus
status
)
{
return
executeSql
();
return
executeSql
();
}
}
});
});
}
else
{
}
else
{
executeSql
();
result
=
executeSql
();
}
}
list
.
add
(
result
);
}
}
public
List
<
Object
>
executeSql
()
{
public
List
<
Object
>
executeSql
()
{
...
...
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