let's play TDD, tackles closures in java

Tom Hawtin tom.hawtin at oracle.com
Mon Dec 20 05:01:54 PST 2010

On 20/12/2010 10:49, Brian Goetz wrote:

> So, in what thread is the closure going to get executed?  Listeners are generally fired in the EDT (in correctly written programs).  Which means that this code example has a data race, and is therefore broken.

A bit off topic, but: Are you sure? Isn't "generally" a problem?

I am not entirely sure what a correctly written Swing program would look 

"Notification is done on the thread that produced the mutation [...]" in 
AbstractDocument doesn't sound like the EDT.

Swing text attempts to be thread-safe but is all over the place. How do 
you do something as complicated as appending text through the Document 
interface? Swing text is thread-hostile.

Testing a known thread-agnostic use of TableModel is sensible. (Top tip: 
Put a layer of indirection between the body of your code and code that 
uses mutable statics, such as 


More information about the lambda-dev mailing list