Skip to content

Commit

Permalink
add threadCount property to ParallelJUnitTask
Browse files Browse the repository at this point in the history
  • Loading branch information
scarytom committed Mar 7, 2012
1 parent 19f9e00 commit 78b1f79
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/main/java/org/netmelody/panto/task/ParallelJUnitTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

public final class ParallelJUnitTask extends Task {
private RecordingJUnitTask embeddedJUnitTask;
private int threadCount = -1;
private int stripeCount = -1;

public void setStripeCount(int stripeCount) {
Expand All @@ -15,6 +16,13 @@ public void setStripeCount(int stripeCount) {
}
this.stripeCount = stripeCount;
}

public void setThreadCount(int threadCount) {
if (threadCount <= 0) {
throw new BuildException("There must be at least one thread");
}
this.threadCount = threadCount;
}

public RecordingJUnitTask createJUnit() {
try {
Expand All @@ -30,10 +38,17 @@ public RecordingJUnitTask createJUnit() {
public void execute() throws BuildException {
final Parallel parallelTask = (Parallel) getProject().createTask("parallel");
parallelTask.init();
parallelTask.setThreadsPerProcessor(1);

if (threadCount > 0) {
parallelTask.setThreadCount(threadCount);
}
else {
threadCount = Runtime.getRuntime().availableProcessors();
parallelTask.setThreadsPerProcessor(1);
}

if (stripeCount <= 0) {
stripeCount = Runtime.getRuntime().availableProcessors();
stripeCount = threadCount;
}
for (int i = 0; i < stripeCount; i++) {
parallelTask.addTask(embeddedJUnitTask.spawnTaskForStripe(i + 1, stripeCount));
Expand Down

0 comments on commit 78b1f79

Please sign in to comment.