Updates off the Swing EDT

View: New views
4 Messages — Rating Filter:   Alert me  

Updates off the Swing EDT

by Richard-332 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

first-up:
i've just discovered glazed lists and am wetting my pets at the excellent
prospect of replacing lots of my hand-crafted junk code with this stuff.
Thank you and congrats on a great project.  Awesome work!

question:
I've got a list of Thing's that can be updated OFF the swing EDT.
i can see how the combination of ThreadSafeList and SwingThreadProxyEventList
means that updates to the list (insertions, removals) get applied to the
EventTableModel in such a way as to keep swing happy (glazed lists makes
changes happen ON the EDT).

Unfortunately, the Thing's themselves can be updated OFF the EDT, and i worry
about inconsistencies in table painting. For example, while painting the cells
in a row the underlying Thing might have a field value change which could cause
inconsistency in the visual appearance of the row, or worse.

Does GlazedLists help me out in this scenario, or do i have to do something
extra?

Trying to get the hang of it, and liking it so far!
Thanks...
  - Richard.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Updates off the Swing EDT

by Gerrit Cap :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Richard,

First of all I think the logical easy approach would be to "cache" your
Things in a consistent state in the event list chain close to the gui.
you could use a FunctionList for that which use a "cloning" function,
hence when an update to list is performed the functionlist clones the
"update" and your GUI will be consistent. If you want automatic updates
to the list happening when your Things change then you can insert an
ObservableElementList before the FunctionList, supposing that your
Things send property change events using the PropertyChangelistener, you
can use the BeanConnector to link the changes of properties within the
observable element list, or if the use the java.util.Observable pattern
there is also a connector for that, if neither is the case you have to
come up with a connector of your own...

Hope this helps,

Gerrit

Richard wrote:

> Hi,
>
> first-up:
> i've just discovered glazed lists and am wetting my pets at the excellent
> prospect of replacing lots of my hand-crafted junk code with this stuff.
> Thank you and congrats on a great project.  Awesome work!
>
> question:
> I've got a list of Thing's that can be updated OFF the swing EDT.
> i can see how the combination of ThreadSafeList and SwingThreadProxyEventList
> means that updates to the list (insertions, removals) get applied to the
> EventTableModel in such a way as to keep swing happy (glazed lists makes
> changes happen ON the EDT).
>
> Unfortunately, the Thing's themselves can be updated OFF the EDT, and i worry
> about inconsistencies in table painting. For example, while painting the cells
> in a row the underlying Thing might have a field value change which could cause
> inconsistency in the visual appearance of the row, or worse.
>
> Does GlazedLists help me out in this scenario, or do i have to do something
> extra?
>
> Trying to get the hang of it, and liking it so far!
> Thanks...
>   - Richard.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>  

--
-------------------- Marble Consulting ----------------------
Gerrit Cap                      http://www.marble.be/
OO Solutions Engineer           mailto:Gerrit.Cap@...
Marble Consulting               gsm : +32 475 72.94.36
Vinkenbosstraat 13              tel : +32 16 89.50.55
B-3001 Heverlee                 fax : +32 16 89.50.58


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Updates off the Swing EDT

by Richard-332 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Gerrit,

thanks for your response, it does help because it made me aware of FunctionList
and confirmed my suspicion that 'something else' needs to be done.

Cloning is OK for most of my use cases, but i've got one case where i've got in
the order of 10-15 thousand items in the list and the user has multiple
views over those items... not sure if i want to clone all that multiple times!
Luckily in this case i control the entire code so i might make things immutable
so updates are really forced to be replacements which should make the race
conditions go away.

Anyway, putting aside specific cases, i'd like to confirm my general
understanding of the situation:

(1) if you have a mutable list (insertions/deletions) then wrapping it in
ThreadSafeList and using EventTableModel is enough to satisfy Swings EDT rules
even if the mutations to the list are happening OFF the EDT.

(2) if you have mutable items in the list and the items are being mutated ON
the EDT then you can contain them in an ObservableElementList, wrap that in a
ThreadSafeList and use EventTableModel, you will be safe (allows the list to be
changed off EDT, but items must be changed on EDT).

(3) if you have mutable items in the list and the items are being mutated OFF
the EDT then this will cause race conditions in JTable painting unless you do
'something else', such as cloning, or... actually i can't think of anything
else!?!

Would that be a fair synopsis?




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Updates off the Swing EDT

by James Lemieux :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Richard,

   Your 3 points are all spot-on. If you can achieve immutability with your elements, I think that produces the sexiest result, but of course you'll need to consider code already written.

   One note of caution: ThreadSafeList is fine for single-method interactions with an EventList, but keep in mind that you must still manually lock and unlock the list for larger units of atomicity. For example:

Object firstElement = null;
if (!myEventList.isEmpty())
   firstElement = myEventList.get(0);

isn't concurrently correct, even if myEventList is a ThreadSafeList, since the lock of the list pipeline is unlocked between the calls to isEmpty() and get(). So, this should really be written as:


Object firstElement = null;
myEventList.getReadWriteLock().lock();
try {
  if (!myEventList.isEmpty())
     firstElement = myEventList.get(0);
} finally {
  myEventList.getReadWriteLock().unlock();
}

Keep on Glazin' in the free world,

James

On Mon, Sep 28, 2009 at 7:30 AM, Richard <numberoneskier@...> wrote:
Hi Gerrit,

thanks for your response, it does help because it made me aware of FunctionList
and confirmed my suspicion that 'something else' needs to be done.

Cloning is OK for most of my use cases, but i've got one case where i've got in
the order of 10-15 thousand items in the list and the user has multiple
views over those items... not sure if i want to clone all that multiple times!
Luckily in this case i control the entire code so i might make things immutable
so updates are really forced to be replacements which should make the race
conditions go away.

Anyway, putting aside specific cases, i'd like to confirm my general
understanding of the situation:

(1) if you have a mutable list (insertions/deletions) then wrapping it in
ThreadSafeList and using EventTableModel is enough to satisfy Swings EDT rules
even if the mutations to the list are happening OFF the EDT.

(2) if you have mutable items in the list and the items are being mutated ON
the EDT then you can contain them in an ObservableElementList, wrap that in a
ThreadSafeList and use EventTableModel, you will be safe (allows the list to be
changed off EDT, but items must be changed on EDT).

(3) if you have mutable items in the list and the items are being mutated OFF
the EDT then this will cause race conditions in JTable painting unless you do
'something else', such as cloning, or... actually i can't think of anything
else!?!

Would that be a fair synopsis?




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...