Commit aa08a658 by yuwencan

commit

parent 918260e7
......@@ -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) {
......
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();
......
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");
}
}
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);
}
}
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));
// }
}
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;
}
}
<html>
<body>
<h1>hello word!!!</h1>
<p>this is a html page</p>
</body>
</html>
\ No newline at end of file
package shark.arthas.demo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ArthasInActionApplicationTests {
@Test
void contextLoads() {
}
}
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