Updating swing components from an arbitrary thread

Threads that work in the background to support the runtime environment are called .

For example, the clock handler thread, the idle thread, the screen updater thread and the garbage collector thread are all daemon threads.

Treat it with just as much caution as you would unprotected volatile variables in a multi-threaded C or assembly language program.

Reserve it for these few situations: The rest of the time, use synchronized blocks and mutex-protected critical regions since they are easier to think about and get right.

updating swing components from an arbitrary thread-82

Code may work fine then fail as soon as you feed it to an optimising compiler, (likely missing does, however, it might be a useful framework to use to dive in to the detail.To catch yourself pestering Swing from the wrong thread try the Thread Checking Repaint Manager.It checks that all repaint events came from the event thread.We say an object is thread-safe, if we can call it's method, which can change it's state, from multiple thread at same time. String is a thread-safe class , which means you can call any method e.g.from any thread, other than Event Dispatcher Thread(EDT) .

Leave a Reply