Forums Register Login

LinkedList List checkForComodification error

+Pie Number of slices to send: Send
Hello, I have an error that I have no idea how to fix or even what is going wrong here. I can only imagine that something is trying to be added or removed wronly from the linked list while im looping though it. Btu it does not seam like its trying to add things to the list while it running when i debug and print out actions it looks ok to me. Maybe im the switch staement is bad or something.
So this is what i have.
This is the real meat of the program that runs the processes in the linked list and calculates the service time and the wait time and moves them to a higher priority list if needed



I have this method for all for linked list so its pretty much the same for all just the last switch statement is different.


and here is where i run the methods calling them depending on robin starts out as one and the switch controlling that seams to work fine too


Thanks for any help with this
1
+Pie Number of slices to send: Send
while iterating a List you cant remove an element using list reference . use iterator for that . i.e, you can use Iterator for loop instead of compiler syntactic sugar for each loop.
+Pie Number of slices to send: Send
so your saying something like this?
+Pie Number of slices to send: Send
 

Matt Millar wrote:so your saying something like this?



No. You have to use the current Iterator. That's not exposed using a foreach loop, so you have to use an explicit Iterator. And if you want to add during iteration, you have to use an explicit ListIterator.

In the above, you're creating a new Iterator that's positioned before the beginning of the List and has no idea about your current iteration.
+Pie Number of slices to send: Send
I Think this is how to do it but it still gives me the error.
+Pie Number of slices to send: Send
You need to use the Iterator's remove method. Not the List's. That's the whole point of it.

During an iteration, the collection may only be structurally modified through the Iterator that's doing the iteration. That means that if you try to use the collection's methods, or if another Iterator tries to use its methods, you'll get an error. A natural consequence of this is that if we have two or more iterations going on at once, none of them can modify the collection, since that would violate the rules for all the others.
+Pie Number of slices to send: Send
ok so using the new MyProcess mp will not remove it from the linked list.
now I see thanks I got a bit confused why I could not just remove it using the linked list way but now i see thanks again
here is the solution that works pretty well
Would you turn that thing down? I'm controlling a mind here! Look ... look at the tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1899 times.
Similar Threads
3 questions regarding JPanel.
Gradebook
Adjectives for "variable" - automatic/local/member/method/method level/instance/class
Time in a program issues
Scjp Queries
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:30:56.