Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris2018998 committed Oct 22, 2023
1 parent ff7be47 commit 613db2b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
28 changes: 17 additions & 11 deletions src/main/java/org/stone/beetp/pool/JoinTaskHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ private JoinTaskHandle(BeeTask task, JoinTaskHandle parent, int brotherSize, Ato
this.completedCount = completedCount;
}

private static void cancelSubTasks(JoinTaskHandle[] subTaskHandles) {
new Thread() {
public void run() {
for (JoinTaskHandle childHandle : subTaskHandles)
childHandle.cancel(true);
}
}.start();
}

//***************************************************************************************************************//
// 3: task cancel(1) //
//***************************************************************************************************************//
Expand All @@ -75,7 +66,7 @@ public boolean cancel(final boolean mayInterruptIfRunning) {

if (subTaskHandles != null) {
if (this.isRoot) {
cancelSubTasks(subTaskHandles);
new AsynJoinCancelThread(root.subTaskHandles, mayInterruptIfRunning).start();
} else {
for (JoinTaskHandle childHandle : subTaskHandles)
childHandle.cancel(mayInterruptIfRunning);
Expand Down Expand Up @@ -153,7 +144,22 @@ private void handleSubTaskException(Object result) {
pool.getTaskRunningCount().decrementAndGet();
pool.getTaskCompletedCount().incrementAndGet();

cancelSubTasks(root.subTaskHandles);
new AsynJoinCancelThread(root.subTaskHandles, true).start();
}
}

private static class AsynJoinCancelThread extends Thread {
private boolean mayInterruptIfRunning;
private JoinTaskHandle[] subTaskHandles;

AsynJoinCancelThread(JoinTaskHandle[] subTaskHandles, boolean mayInterruptIfRunning) {
this.subTaskHandles = subTaskHandles;
this.mayInterruptIfRunning = mayInterruptIfRunning;
}

public void run() {
for (JoinTaskHandle childHandle : subTaskHandles)
childHandle.cancel(mayInterruptIfRunning);
}
}
}
35 changes: 18 additions & 17 deletions src/main/java/org/stone/beetp/pool/TreeTaskHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ private TreeTaskHandle(BeeTreeTask task, TreeTaskHandle parent, int brotherSize,
this.completedCount = completedCount;
}

private static void cancelTreeSubTasks(TreeTaskHandle[] subTaskHandles) {
new Thread() {
public void run() {
for (TreeTaskHandle childHandle : subTaskHandles)
childHandle.cancel(true);
}
}.start();
}

BeeTreeTask getTreeTask() {
return task;
}
Expand All @@ -79,12 +70,7 @@ public boolean cancel(final boolean mayInterruptIfRunning) {

if (subTaskHandles != null) {
if (this.isRoot) {
new Thread() {//async to cancel children
public void run() {
for (TreeTaskHandle childHandle : subTaskHandles)
childHandle.cancel(mayInterruptIfRunning);
}
}.start();
new AsynTreeCancelThread(subTaskHandles, mayInterruptIfRunning).start();
} else {
for (TreeTaskHandle childHandle : subTaskHandles)
childHandle.cancel(mayInterruptIfRunning);
Expand Down Expand Up @@ -153,7 +139,6 @@ void afterSetResult(final int state, final Object result) {
this.handleTreeSubTaskException(new TaskExecutionException(e));
}
}

break;
}
} while (true);
Expand All @@ -166,7 +151,23 @@ private void handleTreeSubTaskException(Object result) {
pool.getTaskHoldingCount().decrementAndGet();
pool.getTaskRunningCount().decrementAndGet();
pool.getTaskCompletedCount().incrementAndGet();
cancelTreeSubTasks(root.subTaskHandles);

new AsynTreeCancelThread(root.subTaskHandles, true).start();
}
}

private static class AsynTreeCancelThread extends Thread {
private boolean mayInterruptIfRunning;
private TreeTaskHandle[] subTaskHandles;

AsynTreeCancelThread(TreeTaskHandle[] subTaskHandles, boolean mayInterruptIfRunning) {
this.subTaskHandles = subTaskHandles;
this.mayInterruptIfRunning = mayInterruptIfRunning;
}

public void run() {
for (TreeTaskHandle childHandle : subTaskHandles)
childHandle.cancel(mayInterruptIfRunning);
}
}
}

0 comments on commit 613db2b

Please sign in to comment.