Main Thread vs. UI Thread in Java

The Swing single-thread rule: Swing components and models should be created, modified, and queried only from the event-dispatching thread.”—Java Concurrency in Practice, also discussed here and here. If you don’t follow this rule, then you can’t reliably construct, modify or query any component or model that may have assumed that you did follow the rule. A program may appear to work correctly, only to fail mysteriously in a different environment. As violations may be obscure, verify correct usage by using one of the approaches mentioned here.

Leave a Comment