Permalink
Browse files

COM4J-70 re-fix

  • Loading branch information...
1 parent 268f60d commit d01b972923c0f3aceb3dc6a942f2715101c1ad7d @sakamotodesu sakamotodesu committed with May 18, 2012
Showing with 17 additions and 36 deletions.
  1. +17 −28 runtime/src/com4j/ComThread.java
  2. +0 −8 runtime/src/com4j/Task.java
@@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@@ -74,8 +75,7 @@ private ComThread(Thread peer) {
/**
* Tasks that need to be processed.
*/
- private Task<?> taskListHead; // com4j issue 40
- private Task<?> taskListTail;
+ private final List<Task<?>> taskList = Collections.synchronizedList((new LinkedList<Task<?>>()));// com4j issue 70
/**
* The set of live COM objects.
@@ -146,20 +146,17 @@ private void run0() {
while(!canExit()) {
lock.suspend(GARBAGE_COLLECTION_INTERVAL);
- synchronized(this) {
- //Clean up any com objects that need releasing
- collectGarbage();
-
- // do any scheduled tasks that need to be done
- while(taskListHead != null) {
- Task<?> task = taskListHead;
- taskListHead = task.next;
- task.invoke();
-
- //Maybe the task produced some garbage...clean that up
- collectGarbage();
- }
- taskListTail = null; // taskListHead is null after the loop, so the tail should be null as well.
+ //Clean up any com objects that need releasing
+ collectGarbage();
+
+ // do any scheduled tasks that need to be done
+ while (!taskList.isEmpty()) {
+ Task<?> task = taskList.get(0);
+ taskList.remove(0);
+ task.invoke();
+
+ //Maybe the task produced some garbage...clean that up
+ collectGarbage();
}
}
@@ -199,18 +196,10 @@ private void collectGarbage() {
* @param <T> The type of the return value.
* @return The result of the Task
*/
- public <T> T execute(final Task<T> task) {
- synchronized(this) {
- synchronized(task) {
- // add it to the tail
- if(taskListTail != null){
- taskListTail.next = task;
- }
- taskListTail = task;
- if(taskListHead == null){
- taskListHead = task;
- }
- }
+ public <T> T execute(Task<T> task) {
+ synchronized(task) {
+ // add it to the tail
+ taskList.add(task);
// invoke the execution
lock.activate();
@@ -43,8 +43,6 @@ public final T execute(ComThread t) {
* Called from {@link ComThread} to run the task.
*/
final synchronized void invoke() {
- next = null;
-
result = null;
exception = null;
try {
@@ -58,12 +56,6 @@ final synchronized void invoke() {
}
/**
- * Managed by {@link ComThread} to form a linked list from
- * {@link ComThread#taskListHead}.
- */
- Task<?> next;
-
- /**
* Managed by {@link ComThread} to pass the return value
* across threads.
*/

0 comments on commit d01b972

Please sign in to comment.