File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Synchronized tablemodel issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Synchronized tablemodel issue" Watch "Synchronized tablemodel issue" New topic

Synchronized tablemodel issue

Mark Dary

Joined: Jan 16, 2009
Posts: 29
Hi all

I have a very large application that processes 3 record sets (call them a,b,c); each contains from 0 to 100,000 record objects (these come from raw data, not a database), and these record sets arrive at various unknown intervals via different threads.

When the first record set (a) is complete I process it to extract various fields which are put into a Map of table records; when record set b is complete I extract some fields to add to the records already in the map; and then I do the same for record set c.

Once complete I show the (read only) table on screen. The whole process then repeats (for example after anything from a few milliseconds to 30 seconds later).

If the interval between displaying the current map (via the EDT) and processing the next set of records is long enough, everything is fine.

However if the interval decreases there is some kind of synchronization issue that I need help with.

In the example you may need to decrease the sleep time and/or increase the number of records.

Note that the error various, eg null pointer, array bounds exception, etc.

If anyone can help it would be greatly appreciated.

Mark Dary

Joined: Jan 16, 2009
Posts: 29
Sorry to be pain guys and girls, but this has been driving me nuts for a couple of days.

Could anyone please, please help with the post?


K. Tsang

Joined: Sep 13, 2007
Posts: 3130

Honestly your code is kind of long to digest. It will be better to identify the section you found problematic.

K. Tsang JavaRanch SCJP5 SCJD OCPJP7 OCPWCD5 OCPBCD5 OCPWSD5 OCMJEA5 part 1 part 2/3
VarunKumar Mallisetty
Ranch Hand

Joined: Jun 18, 2006
Posts: 31
Your code does not follow this rule --> "Once a Swing component has been realized, all code that might affect or depend on the state of that component should be executed in the event-dispatching thread." Read this for more info.

SCJP 6.0
Mark Dary

Joined: Jan 16, 2009
Posts: 29
Hi all

The original code I posted is a complete example (cut,past,compile) to show the problem, the real app has 5 packages with around 100 classes.

I have now changed it so all GUI work is in the EDT (I think) and it works fine.

The next part (I think I'm almost finished) is finding a good synchronization point.

In the original example the makeData() method simulates the raw data that can be received and processed, this can be executed concurrently, anything from 1 to several hundred times.

As I said I think I am almost finished, if anyone is interested I will post a complete example.


I agree. Here's the link:
subject: Synchronized tablemodel issue
It's not a secret anymore!