谁能说出为什么在以下代码段中使用 aFutureTask不起作用?
我的理解是我们可以使用FutureTask,对吗?
给出一个完整的描述:
我在我的代码中偶然发现了一些微妙的错误。
简而言之,我创建了一个使用 aSingleThreadPoolExecutor来运行Callables 作为参数传递的类。
我使用它来运行后台任务并在 Eclipse 应用程序中显示进度对话框。
代码是:  
public class TaskRunner <T>  {  
    final static ExecutorService threadPool = Executors.newSingleThreadExecutor();  
    private T taskResult;  
    public T runTask(Callable<T> task, Shell currentShell) throws CustomException{          
        if(currentShell == null){  
            currentShell = new Shell();  
        }  
        final Callable<T> taskToRun = task;       
        ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(currentShell);  
        try {  
            progressDialog.run(false, true, new IRunnableWithProgress() {  
                @SuppressWarnings("unchecked")  
                @Override  
                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {  
                    monitor.beginTask("Saving your data!", 100);  
                    FutureTask<T> task = createTask(taskToRun);  
                    Future<?> result = threadPool.submit(task);  
                    while(!result.isDone()){  
                        monitor.worked(1);  
                    }                     
                    try {  
                        taskResult = (T) result.get();  
                        if(taskResult == null){  
                            System.out.println("Result here in return is NULL!");  
                        }  
                    } catch (ExecutionException e1) {  
                        logger.error(e1);  
                    }   
                    catch(Exception e){  
                        logger.error(e);  
                    }               
                }  
            });  
        } catch (InvocationTargetException e) {  
            logger.error(e);  
        } catch (InterruptedException e) {  
            logger.error(e);  
        }       
        return taskResult;  
    }  
    private static <T> FutureTask<T> createTask(Callable<T> theTask){  
        return new FutureTask<T>(theTask);   
    }  
}  
和代码任务:
public class MyTask implements Callable<ComplexObject> {    
    private Util helper;  
    private String filePath;  
    public LoadKeystoreTask(Util helper, String filePath) {  
        this.helper = helper;     
        this.filePath = filePath;  
    }  
    @Override  
    public Container call() throws Exception {        
        ComplexObject result = helper.loadData(filePath);  
        if(result == null){  
            System.out.println("ComplexObject IS NULL!");  
        }  
        else{  
            System.out.println("ComplexObject IS NOT NULL!");  
        }   
        return result;  
    }  
}   
问题:
虽然helper.loadData正确地返回了结果(通过调试和打印语句验证)这一行:  
taskResult = (T) result.get(); 
总是null。_ 
即为了简化它被打印:  
复杂对象不为空!
这里的结果是 NULL!
经验证,这是由提交FutureTask. 
如果我提交一个Callable:
即更改为:
Future<?> result = threadPool.submit(taskToRun);
有用!为什么 wrapping withFutureTask会导致这个问题?