Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace synchronized block with ReentrantLock to avoid possible thread pinning with virtual threads (Java 21) #208

Merged
merged 1 commit into from
Sep 8, 2024

Conversation

ofaizulin
Copy link
Contributor

It's recommended to avoid using synchronized block with VirtualThreads. Spring Boot starting from 3.2 and other frameworks now allow to run using virtual threads, so it's small, but valuable change for such scenarios.

Copy link

sonarcloud bot commented Jun 3, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@mweirauch
Copy link
Owner

Just for the record:

i7-6820HQ, Fedora 40, 8.0.422-tem; JMX 1.33:

(11.0.24-tem, 17.0.12-tem and 21.0.4-tem with pretty much identical results)

# before

Benchmark                                                          Mode  Cnt        Score         Error   Units
ProcfsStatusBenchmark.collectAverage                               avgt    5       21,530 ±       0,330   ns/op
ProcfsStatusBenchmark.collectAverageContended                      avgt    5       22,660 ±       0,151   ns/op
ProcfsStatusBenchmark.collectSingle                                  ss    5  6020898,400 ± 4289315,078   ns/op

# after

Benchmark                                                          Mode  Cnt        Score         Error   Units
ProcfsStatusBenchmark.collectAverage                               avgt    5       21,517 ±       0,192   ns/op
ProcfsStatusBenchmark.collectAverageContended                      avgt    5       22,576 ±       0,224   ns/op
ProcfsStatusBenchmark.collectSingle                                  ss    5  5290317,400 ± 2752044,273   ns/op

@mweirauch mweirauch added this to the next milestone Sep 8, 2024
@mweirauch mweirauch merged commit 4cba70e into mweirauch:main Sep 8, 2024
4 checks passed
@mweirauch mweirauch changed the title Replace synchronized block with ReentrantLock to avoid possible thread pinning with virtual threads (java 21) Replace synchronized block with ReentrantLock to avoid possible thread pinning with virtual threads (Java 21) Sep 8, 2024
@mweirauch
Copy link
Owner

Thanks for the contribution @ofaizulin! Sorry it took me so long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants