Skip to content

Commit

Permalink
Merge branch 'GAMA_1.8.2' of https://github.com/gama-platform/gama in…
Browse files Browse the repository at this point in the history
…to GAMA_1.8.2
  • Loading branch information
ptaillandier committed May 6, 2022
2 parents 7d50289 + 3621175 commit 3279e73
Show file tree
Hide file tree
Showing 7 changed files with 1,103 additions and 1,071 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class HeadlessStatement extends AbstractStatement {
*/
public HeadlessStatement(final IDescription desc) {
super(desc);
processorQueue = new ExecutorBasedSimulationRuntime(this.numberOfThread);
processorQueue = new ExecutorBasedSimulationRuntime();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,8 @@ public void run() {
}

/** The executor. */
final ThreadPoolExecutor executor;

/**
* Instantiates a new local simulation runtime.
*/
public ExecutorBasedSimulationRuntime() {
this(UNDEFINED_QUEUE_SIZE);
}
ThreadPoolExecutor executor;
int numberOfThreads = UNDEFINED_QUEUE_SIZE;

/**
* Sets the number of threads.
Expand All @@ -76,43 +70,53 @@ public ExecutorBasedSimulationRuntime() {
*/
@Override
public void setNumberOfThreads(final int n) {
executor.setMaximumPoolSize(n);
numberOfThreads = n;
if (executor != null && n != executor.getMaximumPoolSize()) {
executor.shutdown();
executor = null;
}
}

/**
* Gets the number of threads.
*
* @return the number of threads
*/
public int getNumberOfThreads() { return executor.getMaximumPoolSize(); }
public int getNumberOfThreads() { return numberOfThreads; }

/**
* Instantiates a new local simulation runtime.
*
* @param n
* the number of cores asked
*/
public ExecutorBasedSimulationRuntime(final int n) {
executor = new ThreadPoolExecutor(n, n, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());

private void createNewExecutor() {
executor = new ThreadPoolExecutor(numberOfThreads, numberOfThreads, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>());
executor.setRejectedExecutionHandler((r, executor) -> {
if (r instanceof OwnRunnable or) {
DEBUG.ERR("The execution of " + or.sim.getExperimentID() + " has been rejected");
}
});
}

@Override
public void execute(final Runnable r) {
executor.execute(r);
getExecutor().execute(r);
}


@Override
public void pushSimulation(final IExperimentJob s) {
executor.execute(new OwnRunnable(s));
getExecutor().execute(new OwnRunnable(s));
}

@Override
public boolean isPerformingSimulation() { return executor.getActiveCount() > 0; }
public boolean isPerformingSimulation() { return getExecutor().getActiveCount() > 0; }

ThreadPoolExecutor getExecutor() {
if (executor == null) { createNewExecutor(); }
return executor;
}

}
10 changes: 10 additions & 0 deletions ummisco.gama.feature.dependencies/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1416,4 +1416,14 @@
fragment="true"
unpack="false"/>

<plugin
id="org.eclipse.equinox.launcher.cocoa.macosx.aarch64"
os="macosx"
ws="cocoa"
arch="aarch64"
download-size="0"
install-size="0"
version="0.0.0"
fragment="true"/>

</feature>

0 comments on commit 3279e73

Please sign in to comment.