looking for example of problems when accessing GUI items in non eventdispatch thread

A

Alex Hunsley

I'm looking for ideas for some test code that demonstrates that
accessing GUI items (in Swing) from a thread other than the event
dispatch thread leads to problems.
Ideally, I want to write a small app that does things the "bad way" and
ably (and repeatedly) demonstrates that a problem arises. Anyone have
any ideas of a way to do this?

The nearest parallel to the sort of thing I'm thinking of is the java
program on Sun's site that demonstrates that getting and putting items
into a cubbyhole, without appropriate sychronisation locks, results in
some items being not 'got' at all, or got more than one time....

thanks
alex
 
M

Matt Humphrey

Alex Hunsley said:
I'm looking for ideas for some test code that demonstrates that
accessing GUI items (in Swing) from a thread other than the event
dispatch thread leads to problems.
Ideally, I want to write a small app that does things the "bad way" and
ably (and repeatedly) demonstrates that a problem arises. Anyone have
any ideas of a way to do this?

The nearest parallel to the sort of thing I'm thinking of is the java
program on Sun's site that demonstrates that getting and putting items
into a cubbyhole, without appropriate sychronisation locks, results in
some items being not 'got' at all, or got more than one time....

Just do it. Create a thread that changes the properties of any of the UI
elements. The more frequently threads change things the sooner you'll see
things messed up.

Cheers,
Matt Humphrey (e-mail address removed) http://www.iviz.com/
 
B

Babu Kalakrishnan

Alex said:
I'm looking for ideas for some test code that demonstrates that
accessing GUI items (in Swing) from a thread other than the event
dispatch thread leads to problems.
Ideally, I want to write a small app that does things the "bad way" and
ably (and repeatedly) demonstrates that a problem arises. Anyone have
any ideas of a way to do this?

Try adding and deleting rows from a JList or JTable periodically from
another thread. Sooner or later you are bound to get an
ArrayIndexOutOfBoundsException.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top