Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

Mark Timeouts' thread as daemon and name it #4

Merged
merged 3 commits into from
Apr 14, 2018
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.0.6] - 2018-04-14

* Mark Timeouts' thread as daemon and name it. ([#4](https://github.com/rnorth/duct-tape/pull/4))

## [1.0.5] - 2016-02-20

* Add retry-until-count option (as alternative to until timeout) to `Unreliables`
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/org/rnorth/ducttape/timeouts/Timeouts.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.jetbrains.annotations.NotNull;

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

import static org.rnorth.ducttape.Preconditions.check;

Expand All @@ -11,7 +12,17 @@
*/
public class Timeouts {

private static final ExecutorService EXECUTOR_SERVICE = Executors.newCachedThreadPool();
private static final ExecutorService EXECUTOR_SERVICE = Executors.newCachedThreadPool(new ThreadFactory() {

final AtomicInteger threadCounter = new AtomicInteger(0);

@Override
public Thread newThread(@NotNull Runnable r) {
Thread thread = new Thread(r, "ducttape-" + threadCounter.getAndIncrement());
thread.setDaemon(true);
return thread;
}
});

/**
* Execute a lambda expression with a timeout. If it completes within the time, the result will be returned.
Expand Down