Skip to content

Commit

Permalink
#60 check for max threads
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Apr 23, 2018
1 parent 7ec0337 commit 2a5d637
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/io/wring/agents/Routine.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ public void start() {
@Override
@SuppressWarnings("PMD.PrematureDeclaration")
public void run() {
// @checkstyle MagicNumber (1 line)
if (Thread.getAllStackTraces().size() > 64) {
throw new IllegalStateException(
String.format(
"Too many threads already, can't start: %s",
String.join(
"; ",
new Mapped<>(
Thread::getName, Thread.getAllStackTraces().keySet()
)
)
)
);
}
final long start = System.currentTimeMillis();
final Collection<Future<?>> futures = new ArrayList<>(this.threads);
final ExecutorService runner = Executors.newFixedThreadPool(
Expand Down

0 comments on commit 2a5d637

Please sign in to comment.