2011-03-22 87 views
1

我看到一个人不能/愿意更改长期运行方法返回Future<Something>而不是仅仅<Something>的问题。不幸的是,该方法也从AWT线程中调用,并带来已知的后果。我告诉过他,他在做废话,但可能会有这种可能性。他可以从他的方法中启动一个SwingWorker(或其他),并在等待完成时处理AWT队列。有没有办法从自己的方法处理AWT队列?

我的意思是这样

public Something aLongRunningMethodCalledFromTheAwtThread() { 
    FutureTask<Something> future = new FutureTask<Something>(...); 
    EventQueue eventQueue = Toolkit.getEventQueue(); 
    while (true) { 
     if (future.isDone()) return future.get(); 
     AWTEvent event = eventQueue.getCurrentEvent(); 
     if (event==null) { 
      waitForAWhile(); 
     } else { 
      eventQueue.pop(); // <---- is protected 
      process(event); // <---- BUT HOW??? 
     } 
    } 
} 

据我所知,这样的事情得到在其他框架中完成的,我不知道这是否可能在Swing/AWT吗?

回答

0

当右侧解决方案已经存在时,实施上行解决方案毫无意义。该方法需要作为单独的线程执行。期。

+0

+1顽抗无赖会考虑一个[延续](http://en.wikipedia.org/wiki/Continuation_passing_style#Continuations_as_objects)吗? – trashgod 2011-03-22 02:20:21

+0

这就是我写的*我也告诉过他,所以你不给我提供任何信息。期。 – maaartinus 2011-03-22 02:51:53

+0

@trashgod我不这么认为,要么他一直误解AWT,要么他从另一个框架中学到了东西。 – maaartinus 2011-03-22 02:58:44

相关问题