Skip to content

Commit

Permalink
下一步首页点击
Browse files Browse the repository at this point in the history
  • Loading branch information
zenofung committed Jul 26, 2022
1 parent ad0606a commit e9869c5
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 7 deletions.
53 changes: 53 additions & 0 deletions wine/src/main/java/com/wine/game/wine/common/DeadLock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.wine.game.wine.common;
/**
* @description:
#   Codes are far away from bugs with the animal protecting   
#        神兽保佑,代码无bug 
* @author: zeno fung
*
* @create: 2022-07-26 10:25
*/
public class DeadLock {
private static Integer resource1 = 1 ;
private static Integer resource2 = 2 ;
static class Thread1 implements Runnable{
@Override
public void run() {
synchronized (resource1){
try {
System.out.println(getClass().getName()+" obtains the lock of resource1!");
Thread.sleep(500);
synchronized (resource2) {
System.out.println(getClass().getName()+" obtains the lock of resource2!");
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
static class Thread2 implements Runnable{
@Override
public void run() {
synchronized (resource2){
try {
System.out.println(getClass().getName()+" obtains the lock of resource2!");
Thread.sleep(500);
synchronized (resource1) {
System.out.println(getClass().getName()+" obtains the lock of resource1!");
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
new Thread(new Thread1()).start();
new Thread(new Thread2()).start();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ public String getInfo(){
return info;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
import com.wine.game.wine.security.service.SysLoginService;
import com.wine.game.wine.security.service.TokenService;
import com.zenofung.common.utils.R;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
Expand All @@ -26,6 +30,7 @@
*/
@RestController
@RequestMapping("wine/")
@Slf4j
public class LoginController {

@Autowired
Expand All @@ -52,6 +57,94 @@ public R getInfo()
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
return R.ok().put("user", loginUser);
}
/**
* 获取用户信息
*
* @return 用户信息
*/
@GetMapping("good")
public String good()
{
return "good";
}

@GetMapping("infiniteLoop2")
public void infiniteLoop2(){
log.info("进入");
//死锁
try {
Thread.sleep(100000000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

@GetMapping("infiniteLoop3")
public void infiniteLoop3(){
log.info("进入3");
new Thread(()->{
try {
Thread.sleep(500000);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
}

@GetMapping("infiniteLoop")
public void infiniteLoop(){
log.info("进入");
//死锁
new Thread(new Thread1()).start();
new Thread(new Thread2()).start();
//堆溢出
// List<byte[]> list = new ArrayList<byte[]>();
// for(int i =0;i<1024000;i++) {
// list.add(new byte[1024*1024]);
// }
// List list=new ArrayList();
// Thread thread=new Thread(new MyThread01());
// thread.setName("zeno_Thread");
// thread.start();
// new Thread(()->{

// }).start();

}
private static Integer resource1 = 1 ;
private static Integer resource2 = 2 ;
static class Thread1 implements Runnable{
@Override
public void run() {
synchronized (resource1){
try {
System.out.println(getClass().getName()+" obtains the lock of resource1!");
Thread.sleep(500);
synchronized (resource2) {
System.out.println(getClass().getName()+" obtains the lock of resource2!");
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
static class Thread2 implements Runnable{
@Override
public void run() {
synchronized (resource2){
try {
System.out.println(getClass().getName()+" obtains the lock of resource2!");
Thread.sleep(500);
synchronized (resource1) {
System.out.println(getClass().getName()+" obtains the lock of resource1!");
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new ObjectEncoder());
// 以块的方式来写的处理器
ch.pipeline().addLast(new ChunkedWriteHandler());


/*
说明:
1、http数据在传输过程中是分段的,HttpObjectAggregator可以将多个段聚合
Expand All @@ -120,8 +118,6 @@ protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(binaryWebSocketFrameHandler);
// 自定义的handler,处理业务逻辑
ch.pipeline().addLast(webSocketHandler);


}
});
// 配置完成,开始绑定server,通过调用sync同步方法阻塞直到绑定成功
Expand Down Expand Up @@ -156,7 +152,5 @@ public void init() {
}).start();

}



}
47 changes: 47 additions & 0 deletions wine/tomcat假死
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@


命令: tail -100f localhost_access_log

通过下面的命令查看实时的日志,执行完下面的查看日志的命令后,而后再次申请下程序,在日志中并没有发现申请记录,阐明tomcat处于一种假死状态,上面接着排查。




网络查看
CLOSE_WAIT过多情况
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

netstat -an | grep "CLOSE_WAIT"

ss -ant


gc 情况查看
jstat -gcutil 【pid】 1000


gc 内存情况
jmap -heap 进程ID
jmap -histo 进程ID



①、应用 jstack 命令导出以后JVM的线程dump快照,而后看看dump中线程都在干什么?
命令:jstack pid >> jvmThreadDump.log

count=`cat jstack1.log | grep java.lang.Thread.State | wc -l`; wait=`cat jstack1.log | grep WAITING | wc -l`; a=`echo | awk "{print $wait/$count*100}"`; echo "$a%"




一般针对内存泄露,除了开发代码的时候,就进行规范之后,等运行之后,要查看该问题,特别是线上环境的话,最好将完整的JVM堆栈信息给dump下来。这个时候可以使用以下命令:

jmap -dump:file=heap-dump.bin 24118

指定为二进制文件
jmap -dump:format=b,file=heap-dump.bin <14365>



tar -czvf li.zip.tar li
tar -cvf archive_name.tar directory_to_compress

0 comments on commit e9869c5

Please sign in to comment.