[
https://issues.apache.org/jira/browse/PIVOT-747?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13037714#comment-13037714
]
Andrei Pozolotin commented on PIVOT-747:
----------------------------------------
this is my current pusher-popper
public abstract class EQ_Runner implements Runnable {
protected final Logger log = LoggerFactory.getLogger(getClass());
private final String name;
public EQ_Runner(String name) {
this.name = name;
}
private boolean isDispatchThread() {
return EventQueue.isDispatchThread();
}
private void assertEventDispatchThread() {
if (isDispatchThread()) {
return;
} else {
String message = "must be in EDT";
log.error(message);
throw new IllegalStateException(message);
}
}
private EventQueue getSystemQueue() {
return Toolkit.getDefaultToolkit().getSystemEventQueue();
}
private class ExtraQueue extends EventQueue {
@Override
public void pop() {
try {
super.pop();
} catch (Throwable e) {
log.error("", e);
}
}
}
protected abstract void runCore() throws Exception;
@Override
public final void run() {
try {
runCore();
} catch (Throwable e) {
log.error("", e);
}
}
// http://bugs.sun.com/view_bug.do?bug_id=6424157
// http://netbeans.org/bugzilla/show_bug.cgi?id=90590
//
http://code.google.com/p/javafxdemos/source/browse/ModalDialog/src/modaldialog/EventQueueUtils.java
public final void execute() {
// main EQ; main EDT;
assertEventDispatchThread();
// log.debug("START : {} : {}", isDispatchThread(),
getSystemQueue());
// log.debug("### thread id : {}",
Thread.currentThread().getId());
EventQueue mainQueue = getSystemQueue();
ExtraQueue workQueue = new ExtraQueue();
Thread worker = new Thread(this, name);
// context: switch new
// drain main EQ into work EQ
// start work EDT
mainQueue.push(workQueue);
// worker uses work EDT
worker.start();
// block old main EDT
try {
worker.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
// context: restore old
// drain work EQ into main EQ;
// stop old main EDT; start new main EDT; stop work EDT;
workQueue.pop();
// NOTE: this is no longer a EDT form "pedantic point of view"
// assertEventDispatchThread();
// log.debug("FINISH : {} : {}", isDispatchThread(),
getSystemQueue());
}
}
> pivot & blocking edt
> --------------------
>
> Key: PIVOT-747
> URL: https://issues.apache.org/jira/browse/PIVOT-747
> Project: Pivot
> Issue Type: Improvement
> Components: wtk
> Affects Versions: 2.0
> Reporter: Andrei Pozolotin
>
> Greg, hello;
> in this thread:
> http://mail-archives.apache.org/mod_mbox/pivot-user/201001.mbox/%[email protected]%3E
> your final word is:
> "Sorry, it is not possible"
> but I know that you know that it is possible :-)
> the reason I need this is same as Martin here:
> http://netbeans.org/bugzilla/show_bug.cgi?id=90590
> namely: do some cleanup after shutdown was requested and confirmed:
> org.apache.pivot.wtk.Application
> public boolean shutdown(boolean optional) throws Exception;
> since you call shutdown(boolean optional) from EDT I need to block it, using
> this approach:
> http://bugs.sun.com/view_bug.do?bug_id=6424157
> wich "almost works", except you have this check everywhere:
> Container.assertEventDispatchThread();
> which fails, as described above:
> http://bugs.sun.com/view_bug.do?bug_id=6424157
> due to EventQueue.isDispatchThread() failing on the "T1 vs T1*" distinction
> my request is this:
> do you think you could make
> Container.assertEventDispatchThread();
> less pedantic, and allow both "current and past/next" EDT threads to pass
> which are created during EventQueue push() / pop()
> thanks!
> Andrei
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira