1 package com4j; 2 3 import java.util.concurrent.Callable ; 4 5 10 abstract class Task<T> implements Callable <T> { 11 public abstract T call(); 12 13 14 17 public final T execute() { 18 if( ComThread.isComThread() ) 19 return call(); 21 else 22 return ComThread.get().execute(this); 24 } 25 26 public final T execute(ComThread t) { 27 if(Thread.currentThread()==t) 28 return call(); 30 else 31 return t.execute(this); 33 } 34 35 38 final synchronized void invoke() { 39 assert next!=null; 40 next = null; 41 42 result = null; 43 exception = null; 44 try { 45 result = call(); 46 } catch( RuntimeException e ) { 47 exception = e; 48 } 49 50 notify(); 52 } 53 54 58 Task<?> next; 59 60 64 T result; 65 66 70 RuntimeException exception; 71 } 72 | Popular Tags |