diff --git a/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/AbstractBackend.java b/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/AbstractBackend.java index aab0a6d68e1..b6a279d5488 100644 --- a/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/AbstractBackend.java +++ b/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/AbstractBackend.java @@ -16,12 +16,11 @@ */ package org.apache.jackrabbit.oak.spi.blob.data; +import org.apache.commons.lang3.concurrent.BasicThreadFactory; + import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.ThreadPoolExecutor; - -import org.apache.jackrabbit.oak.spi.blob.data.util.NamedThreadFactory; /** * Abstract Backend which has a reference to the underlying {@link CachingDataStore} and is @@ -168,8 +167,8 @@ protected Executor createAsyncWriteExecutor() { Executor asyncExecutor; if (dataStore.getAsyncUploadLimit() > 0 && getAsyncWritePoolSize() > 0) { - asyncExecutor = (ThreadPoolExecutor) Executors.newFixedThreadPool(getAsyncWritePoolSize(), - new NamedThreadFactory(getClass().getSimpleName() + "-write-worker")); + asyncExecutor = Executors.newFixedThreadPool(getAsyncWritePoolSize(), + BasicThreadFactory.builder().namingPattern(getClass().getSimpleName() + "-write-worker-%d").build()); } else { asyncExecutor = new ImmediateExecutor(); } diff --git a/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/CachingDataStore.java b/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/CachingDataStore.java index fbd963eff42..6c2627cb113 100644 --- a/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/CachingDataStore.java +++ b/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/CachingDataStore.java @@ -48,7 +48,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; -import org.apache.jackrabbit.oak.spi.blob.data.util.NamedThreadFactory; +import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -355,7 +355,7 @@ public void init(String homeDir) throws RepositoryException { } } downloadExecService = Executors.newFixedThreadPool(5, - new NamedThreadFactory("backend-file-download-worker")); + BasicThreadFactory.builder().namingPattern("backend-file-download-worker-%d").build()); cache = new LocalCache(path, tmpDir.getAbsolutePath(), cacheSize, cachePurgeTrigFactor, cachePurgeResizeFactor, asyncWriteCache); /* @@ -1281,7 +1281,7 @@ void upload() throws DataStoreException { long startTime = System.currentTimeMillis(); LOG.info(" Uploading [{}] using [{}] threads.", files.size(), threads); ExecutorService executor = Executors.newFixedThreadPool(threads, - new NamedThreadFactory("backend-file-upload-worker")); + BasicThreadFactory.builder().namingPattern("backend-file-upload-worker-%d").build()); int partitionSize = files.size() / (threads); int startIndex = 0; int endIndex = partitionSize; diff --git a/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/util/NamedThreadFactory.java b/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/util/NamedThreadFactory.java deleted file mode 100644 index 606b035bc83..00000000000 --- a/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/util/NamedThreadFactory.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.jackrabbit.oak.spi.blob.data.util; - -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * This class extends {@link ThreadFactory} to creates named threads. - */ -public class NamedThreadFactory implements ThreadFactory { - - private AtomicInteger threadCount = new AtomicInteger(1); - - String threadPrefixName; - - public NamedThreadFactory(String threadPrefixName) { - super(); - this.threadPrefixName = threadPrefixName; - } - - public Thread newThread(Runnable r) { - Thread thread = new Thread(r); - thread.setContextClassLoader(getClass().getClassLoader()); - thread.setName(threadPrefixName + "-" + threadCount.getAndIncrement()); - return thread; - } - -} diff --git a/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/util/package-info.java b/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/util/package-info.java deleted file mode 100755 index 4e2c1e84f93..00000000000 --- a/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/util/package-info.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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. - */ -/* see JCR-4060 */ -@org.osgi.annotation.versioning.Version("2.13.5") -package org.apache.jackrabbit.oak.spi.blob.data.util; diff --git a/oak-blob/src/test/java/org/apache/jackrabbit/oak/spi/blob/data/TestLocalCache.java b/oak-blob/src/test/java/org/apache/jackrabbit/oak/spi/blob/data/TestLocalCache.java index d20f0085fcb..c0cf9dc5686 100644 --- a/oak-blob/src/test/java/org/apache/jackrabbit/oak/spi/blob/data/TestLocalCache.java +++ b/oak-blob/src/test/java/org/apache/jackrabbit/oak/spi/blob/data/TestLocalCache.java @@ -32,7 +32,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; -import org.apache.jackrabbit.oak.spi.blob.data.util.NamedThreadFactory; +import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -344,7 +344,7 @@ public void testConcurrentInitWithStore() { cache.close(); ExecutorService executor = Executors.newFixedThreadPool(10, - new NamedThreadFactory("localcache-store-worker")); + BasicThreadFactory.builder().namingPattern("localcache-store-worker-%d").build()); cache = new LocalCache(cacheDirPath, tempDirPath, 10000000, 0.95, 0.70, pendingFiles); executor.execute(new StoreWorker(cache, byteMap));