LinkedList Throws NoSuchElementException

Hi

I have a object of LinkedList and i m using it as a queue.

while queueing an element from it i use toString() to use its value becouse the values that are being enqueued are of type string

before dequeuing i check it using isEmpty() funtion but some time this funtion returns false and controll goes to else case. and when it dequeue the value it throw and exception NoSuchElementException.

In some cases the size of LinkedList it returns 0 and in some cases its size is equals to the number of values in the queue.

i m using jdk1.4.2_06

Any one can tell me the reason

it happens with irragular intervals of time.... becose values are equeqing and dequeing continously after some time interval.

if i use the jdk1.5 Queue Interface then what could be the advantages over this aproach. in later case i have to change the jdk

[881 byte] By [12345789a] at [2007-11-26 21:44:12]
# 1
I'd be happy to try and help, but I'd have to see some code, I'm afraid.
kevjavaa at 2007-7-10 3:31:49 > top of Java-index,Java Essentials,Java Programming...
# 2
> Any one can tell me the reasonMy guess is that you have multiple threads and that your code isn't thread safe.Kaj
kajbja at 2007-7-10 3:31:49 > top of Java-index,Java Essentials,Java Programming...
# 3
http://forum.java.sun.com/thread.jspa?threadID=5145567
CeciNEstPasUnProgrammeura at 2007-7-10 3:31:49 > top of Java-index,Java Essentials,Java Programming...
# 4
i know i have posted the same questions on two different forums ...you dont need to mention it..........i just want a reasonable answer IF any one has. If you dont then plz dont reply.................
12345789a at 2007-7-10 3:31:49 > top of Java-index,Java Essentials,Java Programming...
# 5

and the real scenrio is there is a servlet that accepts user requests and enqueue them

an other servlet laods a class that has a timer task , this timer task runs after 5 seconds and for the whole length of the queue. it dequeue 25 requests combine them and send to other class for processing it

reqeusts are dequeued in a block the first check whether queue is empty or not if queue is not empty it dequeue it at this point exception ocuures

12345789a at 2007-7-10 3:31:49 > top of Java-index,Java Essentials,Java Programming...
# 6

> i know i have posted the same questions on two

> different forums ...you dont need to mention

> it..........

>

> i just want a reasonable answer IF any one has. If

> you dont then plz dont reply.................

*sigh* It's good that he mentioned it. Now I know that I shouldn't waste any more time on answering this thread.

kajbja at 2007-7-10 3:31:49 > top of Java-index,Java Essentials,Java Programming...
# 7

> i know i have posted the same questions on two

> different forums ...you dont need to mention

> it..........

Don't you think maybe we might have a little better chance of helping if we had all the information?

> i just want a reasonable answer IF any one has. If

> you dont then plz dont reply.................

Just a note of adminition: If you didn't get a satisfactory answer in the other forum, cross-posting it over here probably isn't going to yield a significantly different answer if you continue to refuse to give useful information.

Did you check prior to this if there might be a similar issue prior to yours? Is this LinkedList a field in your servlet, perchance?

http://forum.java.sun.com/thread.jspa?threadID=5140283

kevjavaa at 2007-7-10 3:31:49 > top of Java-index,Java Essentials,Java Programming...
# 8

first i checked

the linkedlist as a public static variable in the servlet to populate

then i tried to have a separete class that has a linkedlist as a class variable i provided a static reference of this class to use for insertion into the list and for removing the elements

but in both cases the result is same.

it is correct that many requests are comming to servlet and all are equeuing

each request first assigned to a vairable and then enqueued.

12345789a at 2007-7-10 3:31:49 > top of Java-index,Java Essentials,Java Programming...
# 9
http://www.jguru.com/faq/view.jsp?EID=150Try synchronizing your LinkedList. I'm not that educated on Concurrency and its issues, though.
kevjavaa at 2007-7-10 3:31:49 > top of Java-index,Java Essentials,Java Programming...