Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

problems with linked lists

17 views
Skip to first unread message

Pep

unread,
Oct 25, 2005, 5:04:04 AM10/25/05
to
I am running the following code and am having problems with it

==========================================================================

while (running.get())
{

try
{
pp.manageClientDispatch(null);

if (pp.requestResults.size() > 0)
{
TTrequest request = pp.requestResults.poll();

if (request != null)
{
request.getMC().finishProcess();
}

}

}
catch(Throwable e)
{
logFatalToFile("TTdispatcher::run Error results size [" +
pp.requestResults.size() + "] " + e.toString(), e);
e.printStackTrace();
}

}
==========================================================================

The linked list requestResults has elements and the program runs but
suddenly starts throwing the following error from the exception catch

==========================================================================
25 Oct 2005 01:56:21 PDT: FATAL - {Thread-0} {Thread-3}
TTdispatcher::run Error results size [10] java.util.NoSuchElementException
java.util.NoSuchElementException
at java.util.LinkedList.remove(Unknown Source)
at java.util.LinkedList.removeFirst(Unknown Source)
at java.util.LinkedList.poll(Unknown Source)
at uk.co.ticketweb.TTserver.TTdispatcher.run(TTdispatcher.java:63)
at java.lang.Thread.run(Unknown Source)
==========================================================================

line 63 is the linked list poll line of code

This happens at random times in the running of the program.

Help.

Cheers,
Pep.

Thomas Hawtin

unread,
Oct 25, 2005, 11:09:04 AM10/25/05
to
Pep wrote:
>
> The linked list requestResults has elements and the program runs but
> suddenly starts throwing the following error from the exception catch
>
> ==========================================================================
> 25 Oct 2005 01:56:21 PDT: FATAL - {Thread-0} {Thread-3}
> TTdispatcher::run Error results size [10] java.util.NoSuchElementException
> java.util.NoSuchElementException
> at java.util.LinkedList.remove(Unknown Source)
> at java.util.LinkedList.removeFirst(Unknown Source)
> at java.util.LinkedList.poll(Unknown Source)
> at uk.co.ticketweb.TTserver.TTdispatcher.run(TTdispatcher.java:63)
> at java.lang.Thread.run(Unknown Source)
> ==========================================================================
>
> line 63 is the linked list poll line of code
>
> This happens at random times in the running of the program.

You appear to accessing the list from multiple threads with no attempt
at thread-safety. Place synchronized blocks around operations on the
list that you want to be done together (including single method calls).

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/

Roedy Green

unread,
Oct 26, 2005, 12:39:47 AM10/26/05
to
On Tue, 25 Oct 2005 10:04:04 +0100, Pep <p...@nowhere.com> wrote,
quoted or indirectly quoted someone who said :

>This happens at random times in the running of the program.

Only a very few of the Collections are thread safe. See
http://mindprod.com/jgloss/threadsafety.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Pep

unread,
Oct 26, 2005, 3:15:34 AM10/26/05
to
Roedy Green wrote:

> On Tue, 25 Oct 2005 10:04:04 +0100, Pep <p...@nowhere.com> wrote,
> quoted or indirectly quoted someone who said :
>
>>This happens at random times in the running of the program.
>
> Only a very few of the Collections are thread safe. See
> http://mindprod.com/jgloss/threadsafety.html

Thanks for the link, I'll have a good read of that.

Foolishly I thought that the collections were thread safe :(

Cheers,
Pep.

Pep

unread,
Oct 26, 2005, 3:16:24 AM10/26/05
to
Thomas Hawtin wrote:

Thanks, Roedy has pointed that out to me. I was blindly assuming that the

0 new messages