Posted By:
Bradford_Maxwell
Posted On:
Monday, March 29, 2004 08:23 AM
You may not be using the right tool for the job. Are you trying to construct a FIFO cache for i/o? Are you trying to create list that has some persistance?
one way you could do this would be as follows:
on the read thread
String readString = null;
While(true){
if (null == (readString = Listiteartor.next())){
if (null != (readString= Listiterator.previous())){
if (previousString.equals(readString){
continue;
}else{
// do whatever you need to with readString
previousString = readString;
continue;
}
}
}
}
This is still somewhat vulnerable to timing - for example if the writing thread should write twice between reads then the first would be lost since we aren't looking any further back than the immediately previous one. Replacing the if's with while's might solve that problem.
This will attempt to construct a cache. FIFO behavior is not guaranteed tho since if there is a double insertion it will be handled FILO.
If you want to use this to construct an insert-ordered list then you will be sabatoging yourself everytime you issue the previous method call since it will put your cursor in the wrong place for the next write.