From: Qu0ll on
I am trying to use a SwingWorker to load some data into a JList but whenever
I try I get exceptions like this:

Exception in thread "AWT-EventQueue-0"
java.lang.ArrayIndexOutOfBoundsException: 15604
at
javax.swing.plaf.basic.BasicListUI.updateLayoutState(BasicListUI.java:1356)
at
javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(BasicListUI.java:1299)
at
javax.swing.plaf.basic.BasicListUI.getPreferredSize(BasicListUI.java:566)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1634)
at javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:769)
at
org.jvnet.substance.SubstanceScrollPaneUI$AdjustedLayout.layoutContainer(SubstanceScrollPaneUI.java:488)
at java.awt.Container.layout(Container.java:1421)
at java.awt.Container.doLayout(Container.java:1410)
at java.awt.Container.validateTree(Container.java:1507)
at java.awt.Container.validate(Container.java:1480)
at
javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:670)
at
javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:127)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

When I load approximately 80,000 rows I get about 3-4 of these exceptions.
The rows still load however (although I cannot tell if any are missing).
You can ignore the use of the Substance look and feel as I have tried with
built-in PLAFs with similar results.

I am using a SwingWorker in the model class for the JList. What I am
basically doing is retrieving each row from a database in the
doInBackground() method and then when I have each row I add it to an
ArrayList and then call publish(). Then, in the process() method I call
fireIntervalAdded() with the index of each row loaded.

It looks like some kind of threading issue but I cannot see why there would
be a problem given that I am using SwingWorker which should ensure that
process() is called on the EDT.

Another issue which may be relevant is that the rows in the list do not
appear until after the last row is loaded. I was expecting to see the list
growing with the scroll bar thumb getting smaller until the last row is
loaded. If I put a Thread.sleep(20) after each row is loaded from the
database then I do see the JList update as we go along but the exceptions
still occur and the loading process takes forever. For some reason it
appears that without the sleep code the JList is getting "overloaded" with
data and instead of updating the display it just freezes until all data is
loaded.

Can anyone see why I am getting exceptions and why the JList doesn't refresh
until all data is loaded? It would be *very* difficult to provide a SSCCE
given that external processes are involved and there are also
confidentiality issues with the code.

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
Qu0llSixFour(a)gmail.com
[Replace the "SixFour" with numbers to email me]

From: Lew on
Qu0ll wrote:
> I am using a SwingWorker in the model class for the JList. What I am
> basically doing is retrieving each row from a database in the
> doInBackground() method and then when I have each row I add it to an
> ArrayList and then call publish(). Then, in the process() method I call
> fireIntervalAdded() with the index of each row loaded.
>
> It looks like some kind of threading issue but I cannot see why there
> would be a problem given that I am using SwingWorker which should ensure
> that process() is called on the EDT.

Even without an SSCCE you could provide more information. It looks like a
memory model issue due to lack of synchronization on the ArrayList.

--
Lew
From: Qu0ll on
"Lew" <noone(a)lewscanon.com> wrote in message
news:hcc3s6$vhb$1(a)news.albasani.net...
> Qu0ll wrote:
>> I am using a SwingWorker in the model class for the JList. What I am
>> basically doing is retrieving each row from a database in the
>> doInBackground() method and then when I have each row I add it to an
>> ArrayList and then call publish(). Then, in the process() method I call
>> fireIntervalAdded() with the index of each row loaded.
>>
>> It looks like some kind of threading issue but I cannot see why there
>> would be a problem given that I am using SwingWorker which should ensure
>> that process() is called on the EDT.
>
> Even without an SSCCE you could provide more information. It looks like a
> memory model issue due to lack of synchronization on the ArrayList.

Hi Lew,

The following is an outline of the relevant part of the list model class.
This code is not meant to compile, it's just meant to show the strategy I
have adopted.

private final List<Row> rows = Collections.synchronizedList(new
ArrayList<Row>());

private class DBLoader extends SwingWorker<Integer, Integer> {

@Override
protected Integer doInBackground() throws Exception {

...

while (moreData) {
// Get next row.
...

rows.add(row);

publish(rows.size() - 1);
}

return null;
}

@Override
protected void process(final List<Integer> chunks) {

for (final Integer i : chunks) {
fireIntervalAdded(this, i, i);
}
}
}

Are there any obvious problems with this strategy? I am sorry that I cannot
provide more detailed code.

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
Qu0llSixFour(a)gmail.com
[Replace the "SixFour" with numbers to email me]

From: Knute Johnson on
Qu0ll wrote:
> "Lew" <noone(a)lewscanon.com> wrote in message
> news:hcc3s6$vhb$1(a)news.albasani.net...
>> Qu0ll wrote:
>>> I am using a SwingWorker in the model class for the JList. What I am
>>> basically doing is retrieving each row from a database in the
>>> doInBackground() method and then when I have each row I add it to an
>>> ArrayList and then call publish(). Then, in the process() method I
>>> call fireIntervalAdded() with the index of each row loaded.
>>>
>>> It looks like some kind of threading issue but I cannot see why there
>>> would be a problem given that I am using SwingWorker which should
>>> ensure that process() is called on the EDT.
>>
>> Even without an SSCCE you could provide more information. It looks
>> like a memory model issue due to lack of synchronization on the
>> ArrayList.
>
> Hi Lew,
>
> The following is an outline of the relevant part of the list model
> class. This code is not meant to compile, it's just meant to show the
> strategy I have adopted.
>
> private final List<Row> rows = Collections.synchronizedList(new
> ArrayList<Row>());
>
> private class DBLoader extends SwingWorker<Integer, Integer> {
>
> @Override
> protected Integer doInBackground() throws Exception {
>
> ...
>
> while (moreData) {
> // Get next row.
> ...
>
> rows.add(row);
>
> publish(rows.size() - 1);
> }
>
> return null;
> }
>
> @Override
> protected void process(final List<Integer> chunks) {
>
> for (final Integer i : chunks) {
> fireIntervalAdded(this, i, i);
> }
> }
> }
>
> Are there any obvious problems with this strategy? I am sorry that I
> cannot provide more detailed code.
>

Are you modifying the ListModel in the doInBackground() method?

--

Knute Johnson
email s/nospam/knute2009/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
From: Qu0ll on
"Knute Johnson" <nospam(a)rabbitbrush.frazmtn.com> wrote in message
news:4aea13d3$0$4488$b9f67a60(a)news.newsdemon.com...
> Qu0ll wrote:
>> "Lew" <noone(a)lewscanon.com> wrote in message
>> news:hcc3s6$vhb$1(a)news.albasani.net...
>>> Qu0ll wrote:
>>>> I am using a SwingWorker in the model class for the JList. What I am
>>>> basically doing is retrieving each row from a database in the
>>>> doInBackground() method and then when I have each row I add it to an
>>>> ArrayList and then call publish(). Then, in the process() method I
>>>> call fireIntervalAdded() with the index of each row loaded.
>>>>
>>>> It looks like some kind of threading issue but I cannot see why there
>>>> would be a problem given that I am using SwingWorker which should
>>>> ensure that process() is called on the EDT.
>>>
>>> Even without an SSCCE you could provide more information. It looks like
>>> a memory model issue due to lack of synchronization on the ArrayList.
>>
>> Hi Lew,
>>
>> The following is an outline of the relevant part of the list model class.
>> This code is not meant to compile, it's just meant to show the strategy I
>> have adopted.
>>
>> private final List<Row> rows = Collections.synchronizedList(new
>> ArrayList<Row>());
>>
>> private class DBLoader extends SwingWorker<Integer, Integer> {
>>
>> @Override
>> protected Integer doInBackground() throws Exception {
>>
>> ...
>>
>> while (moreData) {
>> // Get next row.
>> ...
>>
>> rows.add(row);
>>
>> publish(rows.size() - 1);
>> }
>>
>> return null;
>> }
>>
>> @Override
>> protected void process(final List<Integer> chunks) {
>>
>> for (final Integer i : chunks) {
>> fireIntervalAdded(this, i, i);
>> }
>> }
>> }
>>
>> Are there any obvious problems with this strategy? I am sorry that I
>> cannot provide more detailed code.
>>
>
> Are you modifying the ListModel in the doInBackground() method?

Umm, yes. *blush*

Thanks Knute, it's working now :-)

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
Qu0llSixFour(a)gmail.com
[Replace the "SixFour" with numbers to email me]