Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

invokeLater runnable doesn't run  RSS feed

 
Mike Dahmus
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a chunk of code which is interacting with a cache (threaded) where cache-notification events attempt to kick off a runnable via SwingUtils.invokeLater as below. In my case, there are eleven cache events occurring (I hit all of them with the debugger and with the print statements) but the runnable only actually runs four times.

protected void notifyPostCacheListeners(final CacheEvent ev) {

System.out.println("notifyPostCacheListeners... outside");

Runnable r = new Runnable() {
public void run() {

System.out.println("notifyPostCacheListeners... runnable.run");

if (_cacheListeners != null) {
for (int i = 0; i < _cacheListeners.size(); i++) {
((CacheListener)_cacheListeners.get(i)).cacheUpdate(ev);
}
}
}
};
SwingUtilities.invokeLater(r);
}

It's ALWAYS four times here. That's what's hard to figure out - if I had a race condition, I might expect a different number of runs. (The cacheUpdate call inside the runnable always successfully completes).

Any ideas?
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You were expecting 11 runs?

I am not sure the println command is thread safe. You may want to synchronize calls to it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!