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
918260e7
Commit
918260e7
authored
Mar 18, 2024
by
yuwencan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init commit
parents
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
206 additions
and
0 deletions
+206
-0
.gitignore
+33
-0
pom.xml
+72
-0
src/main/java/shark/arthas/ArthasInActionApplication.java
+13
-0
src/main/java/shark/arthas/demo/线程被锁定或死锁.java
+85
-0
src/main/resources/application.properties
+3
-0
No files found.
.gitignore
0 → 100644
View file @
918260e7
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
pom.xml
0 → 100644
View file @
918260e7
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
shark.arthas
</groupId>
<artifactId>
arthas-in-action
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<name>
arthas-in-action
</name>
<description>
arthas-in-action
</description>
<properties>
<java.version>
1.8
</java.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
<spring-boot.version>
2.6.13
</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-dependencies
</artifactId>
<version>
${spring-boot.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
3.8.1
</version>
<configuration>
<source>
1.8
</source>
<target>
1.8
</target>
<encoding>
UTF-8
</encoding>
</configuration>
</plugin>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<version>
${spring-boot.version}
</version>
<configuration>
<mainClass>
shark.arthas.demo.ArthasInActionApplication
</mainClass>
<skip>
true
</skip>
</configuration>
<executions>
<execution>
<id>
repackage
</id>
<goals>
<goal>
repackage
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
src/main/java/shark/arthas/ArthasInActionApplication.java
0 → 100644
View file @
918260e7
package
shark
.
arthas
.
demo
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
public
class
ArthasInActionApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
ArthasInActionApplication
.
class
,
args
);
}
}
src/main/java/shark/arthas/demo/线程被锁定或死锁.java
0 → 100644
View file @
918260e7
package
shark
.
arthas
.
demo
;
package
shark
.
arthas
.
demo
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.Objects
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.locks.ReentrantLock
;
/**
* @author yuwc
* @ClassName 线程被锁定或死锁
* @description: 线程被锁定或死锁
* @date 2024年03月18日
* @version: 1.0
*/
@RestController
@RequestMapping
(
"01"
)
public
class
线程被锁定或死锁
{
private
ReentrantLock
lock1
=
new
ReentrantLock
();
private
ReentrantLock
lock2
=
new
ReentrantLock
();
@GetMapping
(
"block"
)
public
void
block
()
throws
InterruptedException
{
Thread
th1
=
new
Thread
(
this
::
doBlock
,
"thread1"
);
th1
.
start
();
TimeUnit
.
MILLISECONDS
.
sleep
(
100
);
Thread
th2
=
new
Thread
(
this
::
doBlock
,
"thread2"
);
th2
.
start
();
}
@GetMapping
(
"deadLock"
)
public
void
deadBlock
()
throws
InterruptedException
{
Thread
th1
=
new
Thread
(
this
::
doDeadLock
,
"thread1"
);
th1
.
start
();
// TimeUnit.MILLISECONDS.sleep(50);
Thread
th2
=
new
Thread
(
this
::
doDeadLock
,
"thread2"
);
th2
.
start
();
}
private
synchronized
void
doBlock
()
{
try
{
TimeUnit
.
MINUTES
.
sleep
(
1
);
System
.
out
.
println
(
"method running..."
);
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
private
void
doDeadLock
()
{
try
{
String
threadName
=
Thread
.
currentThread
().
getName
();
if
(
"thread1"
.
equalsIgnoreCase
(
threadName
))
{
if
(
lock1
.
tryLock
(
1
,
TimeUnit
.
MINUTES
))
{
TimeUnit
.
MILLISECONDS
.
sleep
(
100
);
// lock2.lock();
if
(
lock2
.
tryLock
(
1
,
TimeUnit
.
MINUTES
))
{
TimeUnit
.
SECONDS
.
sleep
(
30
);
System
.
out
.
println
(
"method running..."
);
}
}
}
else
{
if
(
lock2
.
tryLock
(
1
,
TimeUnit
.
MINUTES
))
{
TimeUnit
.
MILLISECONDS
.
sleep
(
100
);
// lock1.lock();
if
(
lock1
.
tryLock
(
1
,
TimeUnit
.
MINUTES
))
{
TimeUnit
.
SECONDS
.
sleep
(
30
);
System
.
out
.
println
(
"method running..."
);
}
}
}
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
finally
{
if
(
lock1
.
isLocked
())
{
lock1
.
unlock
();
}
if
(
lock2
.
isLocked
())
{
lock2
.
unlock
();
}
}
}
}
src/main/resources/application.properties
0 → 100644
View file @
918260e7
# 应用服务 WEB 访问端口
server.port
=
8080
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