46
46
/**
47
47
* Basic usage:
48
48
* <ol>
49
- * <li>Put optimisation problems on the solve queue bu calling {@link #putOnQueue(Sense, byte[], FileFormat)}
49
+ * <li>Put optimisation problems on the solve queue by calling {@link #putOnQueue(Sense, byte[], FileFormat)}
50
50
* <li>Check the status of the optimisation by calling {@link #getStatus(String)} – is it {@link Status#DONE}
51
51
* or still {@link Status#PENDING}?
52
52
* <li>Get the result of the optimisation by calling {@link #getResult(String)} – when {@link Status#DONE}
@@ -136,7 +136,6 @@ private static String generateKey() {
136
136
private final ProcessingService myProcessingService = ProcessingService .newInstance ("optimisation-worker" );
137
137
private final BlockingQueue <Problem > myQueue = new LinkedBlockingQueue <>(128 );
138
138
private final ForgetfulMap <String , Optimisation .Result > myResultCache = ForgetfulMap .newBuilder ().expireAfterAccess (Duration .ofHours (1 )).build ();
139
-
140
139
private final ForgetfulMap <String , Status > myStatusCache = ForgetfulMap .newBuilder ().expireAfterAccess (Duration .ofHours (1 )).build ();
141
140
142
141
public OptimisationService () {
@@ -146,9 +145,10 @@ public OptimisationService() {
146
145
Parallelism baseParallelism = Parallelism .THREADS ;
147
146
int nbStrategies = IntegerStrategy .DEFAULT .countUniqueStrategies ();
148
147
149
- myNumberOfWorkers = baseParallelism .divideBy (2 * nbStrategies ).getAsInt ();
148
+ int targetNbWorkers = baseParallelism .divideBy (2 * nbStrategies ).getAsInt ();
149
+ myNumberOfWorkers = Math .max (2 , targetNbWorkers );
150
150
151
- IntegerStrategy integerStrategy = IntegerStrategy .DEFAULT .withParallelism (baseParallelism .divideBy (myNumberOfWorkers ));
151
+ IntegerStrategy integerStrategy = IntegerStrategy .DEFAULT .withParallelism (baseParallelism .divideBy (targetNbWorkers ));
152
152
153
153
myOptimisationOptions = new Optimisation .Options ();
154
154
myOptimisationOptions .integer (integerStrategy );
0 commit comments