tonikelope 6673191404 7.59
Regression fix 7.56 and 7.57 and 7.58 in multi file splitter progressbar
2023-01-01 16:58:21 +01:00

52 lines
1.4 KiB
Java

/*
__ __ _ _ _
| \/ | ___ __ _ __ _| |__ __ _ ___| |_ ___ _ __ __| |
| |\/| |/ _ \/ _` |/ _` | '_ \ / _` / __| __/ _ \ '__/ _` |
| | | | __/ (_| | (_| | |_) | (_| \__ \ || __/ | | (_| |
|_| |_|\___|\__, |\__,_|_.__/ \__,_|___/\__\___|_| \__,_|
|___/
© Perpetrated by tonikelope since 2016
*/
package com.tonikelope.megabasterd;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.Semaphore;
/**
*
* @author tonikelope
*/
public class BoundedExecutor {
private final ExecutorService exec;
private final Semaphore semaphore;
public BoundedExecutor(ExecutorService exec, int bound) {
this.exec = exec;
this.semaphore = new Semaphore(bound);
}
public void submitTask(final Runnable command)
throws InterruptedException {
semaphore.acquire();
try {
exec.execute(new Runnable() {
public void run() {
try {
command.run();
} finally {
semaphore.release();
}
}
});
} catch (RejectedExecutionException e) {
semaphore.release();
}
}
}