Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import software.amazon.s3.analyticsaccelerator.io.physical.impl.PhysicalIOImpl;
import software.amazon.s3.analyticsaccelerator.request.ObjectClient;
import software.amazon.s3.analyticsaccelerator.request.ObjectMetadata;
import software.amazon.s3.analyticsaccelerator.util.NamedThreadFactory;
import software.amazon.s3.analyticsaccelerator.util.ObjectFormatSelector;
import software.amazon.s3.analyticsaccelerator.util.OpenStreamInformation;
import software.amazon.s3.analyticsaccelerator.util.S3URI;
Expand All @@ -62,6 +63,7 @@ public class S3SeekableInputStreamFactory implements AutoCloseable {
private final ExecutorService threadPool;

private static final Logger LOG = LoggerFactory.getLogger(S3SeekableInputStreamFactory.class);
private static final String THREAD_FACTORY_NAME = "s3-analytics-accelerator-";

/**
* Creates a new instance of {@link S3SeekableInputStreamFactory}. This factory should be used to
Expand All @@ -87,7 +89,8 @@ public S3SeekableInputStreamFactory(
// TODO: calling applications should be able to pass in a thread pool if they so wish
this.threadPool =
Executors.newFixedThreadPool(
configuration.getPhysicalIOConfiguration().getThreadPoolSize());
configuration.getPhysicalIOConfiguration().getThreadPoolSize(),
new NamedThreadFactory(THREAD_FACTORY_NAME, true));
this.objectBlobStore =
new BlobStore(
objectClient,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed 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 software.amazon.s3.analyticsaccelerator.util;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/** ThreadFactory that creates named threads with configurable daemon status. */
public class NamedThreadFactory implements ThreadFactory {
private final AtomicInteger threadNumber = new AtomicInteger(1);
private final String namePrefix;
private final boolean daemon;

/**
* Constructor
*
* @param namePrefix name
* @param daemon is daemon
*/
public NamedThreadFactory(String namePrefix, boolean daemon) {
this.namePrefix = namePrefix;
this.daemon = daemon;
}

@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r, namePrefix + threadNumber.getAndIncrement());
t.setDaemon(daemon);
return t;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed 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 software.amazon.s3.analyticsaccelerator.util;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

class NamedThreadFactoryTest {

@Test
void testThreadNaming() {
NamedThreadFactory factory = new NamedThreadFactory("test-", true);

Thread thread1 = factory.newThread(() -> {});
Thread thread2 = factory.newThread(() -> {});

assertEquals("test-1", thread1.getName());
assertEquals("test-2", thread2.getName());
}

@Test
void testDaemonThread() {
NamedThreadFactory factory = new NamedThreadFactory("daemon-", true);

Thread thread = factory.newThread(() -> {});

assertTrue(thread.isDaemon());
}
}
Loading