Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
arthas-in-action
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
虞文灿
arthas-in-action
Commits
aa08a658
Commit
aa08a658
authored
Mar 21, 2024
by
yuwencan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit
parent
918260e7
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
159 additions
and
2 deletions
+159
-2
src/main/java/shark/arthas/ArthasInActionApplication.java
+2
-0
src/main/java/shark/arthas/demo/Sample01.java
+1
-2
src/main/java/shark/arthas/demo/Sample02.java
+20
-0
src/main/java/shark/arthas/demo/Sample03.java
+48
-0
src/main/java/shark/arthas/demo/Sample04.java
+43
-0
src/main/java/shark/arthas/demo/SpringUtil.java
+25
-0
src/main/resources/static/index.html
+7
-0
src/test/java/shark/arthas/demo/ArthasInActionApplicationTests.java
+13
-0
No files found.
src/main/java/shark/arthas/ArthasInActionApplication.java
View file @
aa08a658
...
...
@@ -2,8 +2,10 @@ package shark.arthas.demo;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
@SpringBootApplication
@EnableScheduling
public
class
ArthasInActionApplication
{
public
static
void
main
(
String
[]
args
)
{
...
...
src/main/java/shark/arthas/demo/
线程被锁定或死锁
.java
→
src/main/java/shark/arthas/demo/
Sample01
.java
View file @
aa08a658
package
shark
.
arthas
.
demo
;
...
...
@@ -17,7 +17,7 @@ import java.util.concurrent.locks.ReentrantLock;
*/
@RestController
@RequestMapping
(
"01"
)
public
class
线程被锁定或死锁
{
public
class
Sample01
{
private
ReentrantLock
lock1
=
new
ReentrantLock
();
private
ReentrantLock
lock2
=
new
ReentrantLock
();
...
...
src/main/java/shark/arthas/demo/Sample02.java
0 → 100644
View file @
aa08a658
package
shark
.
arthas
.
demo
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
/**
* ognl -x 3 '#springContext=@shark.arthas.demo.SpringUtil@ac,#springContext.getBean("sample02").execute()'
* @author yuwc
* @ClassName 通过ognl表达式执行方法
* @description: 通过ognl表达式执行方法
* @date 2024年03月21日
* @version: 1.0
*/
@Component
public
class
Sample02
{
@Scheduled
(
fixedDelayString
=
"300000"
)
public
void
execute
(){
System
.
out
.
println
(
"method invoker"
);
}
}
src/main/java/shark/arthas/demo/Sample03.java
0 → 100644
View file @
aa08a658
package
shark
.
arthas
.
demo
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.StopWatch
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.concurrent.TimeUnit
;
/**
* trace shark.arthas.demo.Sample03 handle --skipJDKMethod false
* 新终端 2,使用telnet localhost 3658连接上
* trace shark.arthas.demo.Sample03 methodB --listenerId 3
* trace shark.arthas.demo.Runner doStart --listenerId 3
* @author yuwc
* @ClassName 定位方法执行耗时原因
* @description: 定位方法执行耗时原因
* @date 2024年03月21日
* @version: 1.0
*/
@RestController
@RequestMapping
(
"03"
)
public
class
Sample03
{
@Autowired
Runner
runner
;
@RequestMapping
(
"/useTime"
)
public
void
handle
()
throws
InterruptedException
{
StopWatch
stopWatch
=
new
StopWatch
();
stopWatch
.
start
();
methodA
();
methodB
();
stopWatch
.
stop
();
}
private
void
methodA
(){
System
.
out
.
println
(
"执行methodA"
);
}
private
void
methodB
()
throws
InterruptedException
{
System
.
out
.
println
(
"执行methodB"
);
runner
.
doStart
();
}
}
@Component
class
Runner
{
public
void
doStart
()
throws
InterruptedException
{
TimeUnit
.
SECONDS
.
sleep
(
3
);
}
}
src/main/java/shark/arthas/demo/Sample04.java
0 → 100644
View file @
aa08a658
package
shark
.
arthas
.
demo
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* thread
* thread 线程ID
* @author yuwc
* @ClassName Sample04
* @description: 排查CPU使用率高
* @date 2024年03月21日
* @version: 1.0
*/
@RestController
@RequestMapping
(
"04"
)
public
class
Sample04
{
@RequestMapping
(
"{url}"
)
public
void
handle
(
@PathVariable
(
"url"
)
String
v
){
while
(
true
)
{
}
// if (StringUtils.endsWithIgnoreCase("v1", v)) {
// method(1);
// }else if (StringUtils.endsWithIgnoreCase("v2", v)) {
// method("字符串");
// }else if (StringUtils.endsWithIgnoreCase("v3", v)) {
// method("字符串1", "字符串2");
// }
}
// private void method(int param){
// System.out.println(String.format("param1:%s", param));
// }
// private void method(String param){
// System.out.println(String.format("param1:%s", param));
// }
// private void method(String param1, String param2){
// System.out.println(String.format("param1:%s,param2:%s", param1, param2));
// }
}
src/main/java/shark/arthas/demo/SpringUtil.java
0 → 100644
View file @
aa08a658
package
shark
.
arthas
.
demo
;
import
org.springframework.beans.BeansException
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.stereotype.Component
;
/**
* @author yuwc
* @ClassName SpringUtil
* @description: SpringUtil
* @date 2024年03月21日
* @version: 1.0
*/
@Component
public
class
SpringUtil
implements
ApplicationContextAware
{
public
static
ApplicationContext
ac
;
// public static <T> T getBean(Class<T> tClass){
// return ac.getBean(tClass);
// }
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
ac
=
applicationContext
;
}
}
src/main/resources/static/index.html
0 → 100644
View file @
aa08a658
<html>
<body>
<h1>
hello word!!!
</h1>
<p>
this is a html page
</p>
</body>
</html>
\ No newline at end of file
src/test/java/shark/arthas/demo/ArthasInActionApplicationTests.java
0 → 100644
View file @
aa08a658
package
shark
.
arthas
.
demo
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
class
ArthasInActionApplicationTests
{
@Test
void
contextLoads
()
{
}
}
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