Use a work stealing pool

This commit is contained in:
Tony Garnock-Jones 2020-12-05 00:01:28 +01:00
parent a333659741
commit bb3d822988
2 changed files with 5 additions and 2 deletions

View File

@ -12,7 +12,7 @@ public class Actor implements Executor {
private final static ThreadLocal<Actor> _currentActor = new ThreadLocal<>(); private final static ThreadLocal<Actor> _currentActor = new ThreadLocal<>();
private final static AtomicLong _count = new AtomicLong(0); private final static AtomicLong _count = new AtomicLong(0);
private final static AtomicLong _actorId = new AtomicLong(0); private final static AtomicLong _actorId = new AtomicLong(0);
protected final static ExecutorService _executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); protected final static ExecutorService _executor = Executors.newWorkStealingPool();
protected final static ScheduledExecutorService _scheduledExecutor = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors()); protected final static ScheduledExecutorService _scheduledExecutor = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors());
private final String _name; private final String _name;

View File

@ -5,13 +5,15 @@ import org.syndicate_lang.actors.Actor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static java.lang.Integer.parseInt;
public class Main implements IForwarder { public class Main implements IForwarder {
private List<IForwarder> _actors; private List<IForwarder> _actors;
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
Actor.convenientLogging(); Actor.convenientLogging();
Actor.forObject(new Main(1000000, 10)).syncVoid(Main::boot).await(); Actor.forObject(new Main(parseInt(args[0]), parseInt(args[1]))).syncVoid(Main::boot).await();
Actor.awaitAll(); Actor.awaitAll();
} }
@ -26,6 +28,7 @@ public class Main implements IForwarder {
} }
public void boot() { public void boot() {
Actor.log().info("Available processors: " + Runtime.getRuntime().availableProcessors());
this._actors = new ArrayList<>(); this._actors = new ArrayList<>();
IForwarder me = Actor.ref(this).asyncProxy(IForwarder.class); IForwarder me = Actor.ref(this).asyncProxy(IForwarder.class);
for (int i = 0; i < _nActors; i++) { for (int i = 0; i < _nActors; i++) {