Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

problems with linked lists

Thread view: 
Pep - 25 Oct 2005 10:04 GMT
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 - 25 Oct 2005 16:09 GMT
> The linked list requestResults has elements and the program runs but
> suddenly starts throwing the following error from the exception catch
[quoted text clipped - 13 lines]
>
> 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
Signature

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

Pep - 26 Oct 2005 08:16 GMT
>> 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]
[quoted text clipped - 5 lines]
>>         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
>>
[quoted text clipped - 5 lines]
>
> Tom Hawtin

Thanks, Roedy has pointed that out to me. I was blindly assuming that the
collections were thread safe :(
Roedy Green - 26 Oct 2005 05:39 GMT
>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
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Pep - 26 Oct 2005 08:15 GMT
>>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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.