Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix argon and balloon blocking application shutdown #151

Merged
merged 1 commit into from
Apr 23, 2024
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
2 changes: 1 addition & 1 deletion src/main/java/com/password4j/Argon2Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class Argon2Function extends AbstractHashingFunction

if (parallelism >= 1)
{
service = Executors.newFixedThreadPool(Utils.AVAILABLE_PROCESSORS);
service = Utils.createExecutorService();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/password4j/BalloonHashingFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class BalloonHashingFunction extends AbstractHashingFunction
this.delta = delta;
if (parallelism > 1)
{
this.service = Executors.newFixedThreadPool(Utils.AVAILABLE_PROCESSORS);
this.service = Utils.createExecutorService();
}

}
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/password4j/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -50,6 +53,10 @@ class Utils

private static final int[] FROM_BASE64 = new int[256];

private static final AtomicInteger THREAD_COUNTER = new AtomicInteger(1);

private static final ThreadGroup THREAD_GROUP = new ThreadGroup("Password4j Workers");

static
{
Arrays.fill(FROM_BASE64, -1);
Expand Down Expand Up @@ -655,6 +662,11 @@ static List<byte[]> split(byte[] array, byte delimiter) {
return byteArrays;
}



static ExecutorService createExecutorService() {
return Executors.newFixedThreadPool(AVAILABLE_PROCESSORS, runnable -> {
Thread thread = new Thread(THREAD_GROUP, runnable, "password4j-worker-" + THREAD_COUNTER.getAndIncrement());
thread.setDaemon(true);
return thread;
});
}
}
Loading