You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ak...@apache.org on 2022/10/18 07:50:20 UTC

[netbeans] branch master updated: Provide hints for conversion to Virtual thread executor when thread pools are used (#4592)

This is an automated email from the ASF dual-hosted git repository.

akhileshsingh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new b696342fec Provide hints for conversion to Virtual thread executor when thread pools are used (#4592)
b696342fec is described below

commit b696342fecc1a50e6490c319532676ddda348a94
Author: Meghna Jayan <me...@oracle.com>
AuthorDate: Tue Oct 18 13:20:12 2022 +0530

    Provide hints for conversion to Virtual thread executor when thread pools are used (#4592)
    
    * add hints for using virtual threads
---
 .../netbeans/modules/java/hints/jdk/CanUseVT.java  | 68 ++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/java/java.hints/src/org/netbeans/modules/java/hints/jdk/CanUseVT.java b/java/java.hints/src/org/netbeans/modules/java/hints/jdk/CanUseVT.java
new file mode 100644
index 0000000000..819f940496
--- /dev/null
+++ b/java/java.hints/src/org/netbeans/modules/java/hints/jdk/CanUseVT.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.hints.jdk;
+
+import org.netbeans.api.java.queries.CompilerOptionsQuery;
+import org.netbeans.modules.java.hints.errors.Utilities;
+import org.netbeans.spi.editor.hints.ErrorDescription;
+import org.netbeans.spi.editor.hints.Fix;
+import org.netbeans.spi.editor.hints.Severity;
+import org.netbeans.spi.java.hints.ConstraintVariableType;
+import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
+import org.netbeans.spi.java.hints.Hint;
+import org.netbeans.spi.java.hints.HintContext;
+import org.netbeans.spi.java.hints.TriggerPattern;
+import org.netbeans.spi.java.hints.TriggerPatterns;
+import org.openide.util.NbBundle;
+
+/**
+ *
+ * @author mjayan
+ */
+@NbBundle.Messages({
+    "DN_CanUseVT=Can use Virtual Threads",
+    "DESC_CanUseVT=Can use virtual threads if workload is not CPU bound or number of concurrent tasks is high",
+    "ERR_CanUseVT=Can Use Virtual Thread Executor",
+    "ERR_CanUseThreadPerTask=Can Use Executors.newThreadPerTaskExecutor"
+})
+@Hint(displayName = "#DN_CanUseVT", description = "#DESC_CanUseVT", category = "suggestions", hintKind = Hint.Kind.INSPECTION, severity = Severity.HINT,
+        minSourceVersion = "19")
+public class CanUseVT {
+
+    private static final int VT_PREVIEW_JDK_VERSION = 19;
+
+    @TriggerPatterns({
+        @TriggerPattern(value = "java.util.concurrent.Executors.newFixedThreadPool($size)", constraints = @ConstraintVariableType(variable = "$size", type = "int")),
+        @TriggerPattern(value = "java.util.concurrent.Executors.newFixedThreadPool($size, $factory)", constraints = {
+            @ConstraintVariableType(variable = "$factory", type = "java.util.concurrent.ThreadFactory"),
+            @ConstraintVariableType(variable = "$size", type = "int")}),
+        @TriggerPattern(value = "java.util.concurrent.Executors.newCachedThreadPool()"),
+        @TriggerPattern(value = "java.util.concurrent.Executors.newCachedThreadPool($factory)", constraints
+                = @ConstraintVariableType(variable = "$factory", type = "java.util.concurrent.ThreadFactory"))})
+    public static ErrorDescription compute(HintContext ctx) {
+        if (Utilities.isJDKVersionLower(VT_PREVIEW_JDK_VERSION) && !CompilerOptionsQuery.getOptions(ctx.getInfo().getFileObject()).getArguments().contains("--enable-preview")) {
+            return null;
+        }
+        if (ctx.getVariables().get("$factory") != null) {
+            return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_CanUseThreadPerTask(), new Fix[0]);
+        } else {
+            return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_CanUseVT(), new Fix[0]);
+        }
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists