You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2026/07/30 09:16:08 UTC
(openwebbeans) branch main updated: OWB-1471 Create an annotation to mark implementations as @ThreadSafe
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git
The following commit(s) were added to refs/heads/main by this push:
new 5467642cb OWB-1471 Create an annotation to mark implementations as @ThreadSafe
5467642cb is described below
commit 5467642cbba45fd90d3d1234456692888442f5c3
Author: Mark Struberg <st...@apache.org>
AuthorDate: Thu Jul 30 11:15:09 2026 +0200
OWB-1471 Create an annotation to mark implementations as @ThreadSafe
In which case we don't need to wrap the custom Finder within synchronisations.
---
.../corespi/scanner/AbstractMetaDataDiscovery.java | 4 ++-
.../webbeans/spi/annotations/ThreadSafe.java | 40 ++++++++++++++++++++++
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java b/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
index ed4830c6b..d48856a45 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
@@ -35,6 +35,7 @@ import org.apache.webbeans.spi.BDABeansXmlScanner;
import org.apache.webbeans.spi.BdaScannerService;
import org.apache.webbeans.spi.BeanArchiveService;
import org.apache.webbeans.spi.BeanArchiveService.BeanDiscoveryMode;
+import org.apache.webbeans.spi.annotations.ThreadSafe;
import org.apache.webbeans.util.ClassUtil;
import org.apache.webbeans.util.UrlSet;
import org.apache.webbeans.util.WebBeansUtil;
@@ -181,7 +182,8 @@ public abstract class AbstractMetaDataDiscovery implements BdaScannerService
{
// filter is by design single threaded so if not enforced to be thread safe just make it working
// it is likely the cpu will burn on the jar deflation more than the filter so fill not hurt that much
- if (userFilter != null && !(userFilter instanceof ThreadSafeUserFilter))
+ // If a filter is marked as ThreadSafe, then we don't wrap it.
+ if (userFilter != null && !(userFilter instanceof ThreadSafeUserFilter) && !(userFilter.getClass().isAnnotationPresent(ThreadSafe.class)))
{
userFilter = ThreadSafeUserFilter.wrap(userFilter);
}
diff --git a/webbeans-spi/src/main/java/org/apache/webbeans/spi/annotations/ThreadSafe.java b/webbeans-spi/src/main/java/org/apache/webbeans/spi/annotations/ThreadSafe.java
new file mode 100644
index 000000000..ede41fd47
--- /dev/null
+++ b/webbeans-spi/src/main/java/org/apache/webbeans/spi/annotations/ThreadSafe.java
@@ -0,0 +1,40 @@
+/*
+ * 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.apache.webbeans.spi.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Annotation to mark an implementation as thread-safe.
+ * This can be applied to e.g. xbean-finder filter implementations.
+ */
+@Target({ TYPE, METHOD })
+@Retention(RUNTIME)
+@Documented
+@Inherited
+public @interface ThreadSafe
+{
+}