Re: repaint method and design question
Peter Duniho wrote:
On Tue, 01 Jul 2008 18:36:02 -0700, Lew <lew@lewscanon.com> wrote:
I see nothing in the Javadocs for JComponent#repaint() that indicates
that the method is thread safe.
But you showed us
<http://java.sun.com/products/jfc/tsc/articles/painting/index.html#paint_process>
which explains that repaint() is thread safe. [...]
Where does it do that? And please distinguish between "thread safe" as
in "need not be called on the EDT" and "thread safe" as in "can be
called simultaneously from multiple threads".
I read through that page and was unable to find a clear statement to the
effect of either type of "thread safe". I'd appreciate it if you could
direct me to the portion of the page that you believes does so.
You're absolutely right. It says that the repaint() schedules the painting to
happen on the EDT, not that the action is thread safe in general terms.
In the context of this conversation, that means that it should be thread-safe
enough for the EDT, especially under the assumptions stated by - actually, by
you yourself:
The code being invoked does need to deal with synchronization, possibly.
But when I write code like this, typically the only data being used in the
invoked code is the bare minimum data required to update the GUI.
In particular, the extraction of the relevant information from my model has
already been done, on the same thread that's processing the model, and
copied to some specific place used by the invoked code (sometimes this is
as simple as a "final" local variable used in an anonymous class).
So the promise of the cited article that the repaint() will happen on the EDT
makes it, most of the time, thread-safe enough.
--
Lew