forked from j62/ctbrec
Fix: excessive spawning of threads by the GlobalThreadPool
This commit is contained in:
parent
b677fbbc8c
commit
1cf2d35f74
|
@ -15,14 +15,13 @@ public abstract class MyFreeCamsAbstractUpdateService extends PaginatedScheduled
|
||||||
MyFreeCamsClient client = MyFreeCamsClient.getInstance();
|
MyFreeCamsClient client = MyFreeCamsClient.getInstance();
|
||||||
|
|
||||||
protected List<MyFreeCamsModel> getModels() {
|
protected List<MyFreeCamsModel> getModels() {
|
||||||
List<MyFreeCamsModel> models = client.getModels().stream()
|
List<MyFreeCamsModel> models = client.getModels().stream().toList();
|
||||||
.toList();
|
|
||||||
|
|
||||||
for (Model model : models) {
|
for (Model model : models) {
|
||||||
GlobalThreadPool.submit(() -> {
|
GlobalThreadPool.submit(() -> {
|
||||||
try {
|
try {
|
||||||
client.getSessionState(model);
|
client.getSessionState(model);
|
||||||
model.isOnline(true);
|
model.isOnline();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -1,19 +1,16 @@
|
||||||
package ctbrec;
|
package ctbrec;
|
||||||
|
|
||||||
import java.util.UUID;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class GlobalThreadPool {
|
public class GlobalThreadPool {
|
||||||
|
|
||||||
private static final ExecutorService threadPool = Executors.newCachedThreadPool(r -> {
|
private static final ExecutorService threadPool = Executors.newWorkStealingPool();
|
||||||
Thread t = new Thread(r);
|
|
||||||
t.setDaemon(true);
|
|
||||||
t.setName("GlobalWorker-" + UUID.randomUUID().toString().substring(0, 8));
|
|
||||||
return t;
|
|
||||||
});
|
|
||||||
|
|
||||||
private GlobalThreadPool() {
|
private GlobalThreadPool() {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue