From 3dd47a3b94cdbeb0ef349c8212e7eb1d3d696140 Mon Sep 17 00:00:00 2001 From: Charles Honton Date: Wed, 21 Aug 2024 14:27:02 -0700 Subject: [PATCH 1/5] update AvoidSynchronizedAtMethodLevel message to mention ReentrantLock see https://openjdk.org/jeps/8337395 --- .../category/java/multithreading.xml | 68 +++++++++++++++++-- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/pmd-java/src/main/resources/category/java/multithreading.xml b/pmd-java/src/main/resources/category/java/multithreading.xml index 88750e9ab0..89dde428b3 100644 --- a/pmd-java/src/main/resources/category/java/multithreading.xml +++ b/pmd-java/src/main/resources/category/java/multithreading.xml @@ -12,13 +12,13 @@ Rules that flag issues when dealing with multiple threads of execution. -Method-level synchronization can cause problems when new code is added to the method. -Block-level synchronization helps to ensure that only the code that needs synchronization -gets it. +Method-level synchronization will pin virtual threads and can cause performance problems. Additionally, it can cause +problems when new code is added to the method. Block-level ReentrantLock helps to ensure that only the code that +needs mutual exclusion will be locked. 3 @@ -30,7 +30,7 @@ gets it. + + + Synchronization will pin virtual threads and can cause performance problems. + + 3 + + + //SynchronizedStatement + + + + + + + Date: Thu, 22 Aug 2024 13:54:17 -0700 Subject: [PATCH 2/5] added unit test --- .../AvoidSynchronizedStatementTest.java | 11 +++++++ .../xml/AvoidSynchronizedStatement.xml | 32 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/multithreading/AvoidSynchronizedStatementTest.java create mode 100644 pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/multithreading/xml/AvoidSynchronizedStatement.xml diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/multithreading/AvoidSynchronizedStatementTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/multithreading/AvoidSynchronizedStatementTest.java new file mode 100644 index 0000000000..bb02194212 --- /dev/null +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/multithreading/AvoidSynchronizedStatementTest.java @@ -0,0 +1,11 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.java.rule.multithreading; + +import net.sourceforge.pmd.test.PmdRuleTst; + +class AvoidSynchronizedStatementTest extends PmdRuleTst { + // no additional unit tests +} diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/multithreading/xml/AvoidSynchronizedStatement.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/multithreading/xml/AvoidSynchronizedStatement.xml new file mode 100644 index 0000000000..811db288e9 --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/multithreading/xml/AvoidSynchronizedStatement.xml @@ -0,0 +1,32 @@ + + + + + TEST1 + 1 + + + + + #991 AvoidSynchronizedStatement for static methods + 1 + + + From 93db59bea51292d6c9042301ba28b774aefbaf6b Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 29 Aug 2024 12:41:02 +0200 Subject: [PATCH 3/5] Apply suggestions from code review --- .../resources/category/java/multithreading.xml | 4 ++-- .../xml/AvoidSynchronizedStatement.xml | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pmd-java/src/main/resources/category/java/multithreading.xml b/pmd-java/src/main/resources/category/java/multithreading.xml index 89dde428b3..605829ce67 100644 --- a/pmd-java/src/main/resources/category/java/multithreading.xml +++ b/pmd-java/src/main/resources/category/java/multithreading.xml @@ -30,7 +30,7 @@ needs mutual exclusion will be locked. - TEST1 + Synchronized block in instance method 1 - #991 AvoidSynchronizedStatement for static methods + Synchronized block in static methods 1 + + + + synchronized methods are not flagged - we have a separate rule AvoidSynchronizedAtMethodLevel for that + 0 + From a4cac6b74f26c952f7cdfc973a000feaa3b4f98e Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 29 Aug 2024 12:46:30 +0200 Subject: [PATCH 4/5] Update @chonton as a contributor --- .all-contributorsrc | 3 ++- docs/pages/pmd/projectdocs/credits.md | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index f76cd95f82..bc334b0795 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1929,7 +1929,8 @@ "avatar_url": "https://avatars.githubusercontent.com/u/1444125?v=4", "profile": "http://www.linkedin.com/in/chonton", "contributions": [ - "bug" + "bug", + "code" ] }, { diff --git a/docs/pages/pmd/projectdocs/credits.md b/docs/pages/pmd/projectdocs/credits.md index 7cbe0baec8..f292c30e7e 100644 --- a/docs/pages/pmd/projectdocs/credits.md +++ b/docs/pages/pmd/projectdocs/credits.md @@ -171,7 +171,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Carsten Otto
Carsten Otto

🐛 Charlie Housh
Charlie Housh

🐛 Charlie Jonas
Charlie Jonas

🐛 - Chas Honton
Chas Honton

🐛 + Chas Honton
Chas Honton

🐛 💻 Chen Yang
Chen Yang

🐛 Chotu
Chotu

🐛 Chris Smith
Chris Smith

🐛 From 3c3be3c81dd3fdf0d759c26276fbaebf985ca1cf Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 29 Aug 2024 12:48:14 +0200 Subject: [PATCH 5/5] [doc] Update release notes (#5175) --- docs/pages/release_notes.md | 8 ++++++++ pmd-java/src/main/resources/rulesets/java/quickstart.xml | 1 + 2 files changed, 9 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 39aef42caa..58bd741913 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -14,9 +14,16 @@ This is a {{ site.pmd.release_type }} release. ### 🚀 New and noteworthy +### 🌟 New and changed rules +#### New Rules +* The new Java rule {%rule java/multithreading/AvoidSynchronizedStatement %} finds synchronization blocks that + could cause performance issues with virtual threads due to pinning. + ### 🐛 Fixed Issues * apex-performance * [#5139](https://github.com/pmd/pmd/issues/5139): \[apex] OperationWithHighCostInLoop not firing in triggers +* java-multithreading + * [#5175](https://github.com/pmd/pmd/issues/5175): \[java] Update AvoidSynchronizedAtMethodLevel message to mention ReentrantLock, new rule AvoidSynchronizedStatement * plsql-bestpractices * [#5132](https://github.com/pmd/pmd/issues/5132): \[plsql] TomKytesDespair - exception for more complex exception handler @@ -32,6 +39,7 @@ This is a {{ site.pmd.release_type }} release. because this is an implementation class that should not be used directly. ### ✨ External Contributions +* [#5175](https://github.com/pmd/pmd/pull/5175): \[java] Update AvoidSynchronizedAtMethodLevel message to mention ReentrantLock, new rule AvoidSynchronizedStatement - [Chas Honton](https://github.com/chonton) (@chonton) {% endtocmaker %} diff --git a/pmd-java/src/main/resources/rulesets/java/quickstart.xml b/pmd-java/src/main/resources/rulesets/java/quickstart.xml index 4afb964163..97eb2742da 100644 --- a/pmd-java/src/main/resources/rulesets/java/quickstart.xml +++ b/pmd-java/src/main/resources/rulesets/java/quickstart.xml @@ -279,6 +279,7 @@ +