|
| |||||||||
| Tags: collection, iterator, java, programming language, synchronize, utitlities |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Synchronize an iterator in java
Hello, I have some code which used hashtable and the enumeration. I converted all the hashtable in treemap and enumeration iterator to return, however, at a specific location. Here is the code for it Code: Iterator = it son.keySet().iterator();
while (it.hasNext()) {
String cleTemp = (String)it.next();
Fil fl = ((Thread)son.get(cleTemp));
if (fl.estRelieA(codeElem)) supprimerFil(cleTemp);
} |
|
#2
| |||
| |||
| Re: Synchronize an iterator in java
Hello, I am new to this , but I have a code with me, you can try it See below for the code Code: Set s = Collections.synchronizedSet(son.keySet());
synchronized(s) {
Iterator it = s.iterator();
while (it.hasNext()) {
String str = (String)it.next();
Fil fl = ((Thread)son.get(str));
if (fl.est(codeElem)) supprimerFil(str);
}
} |
|
#3
| |||
| |||
| Re: Synchronize an iterator in java
Hello, Alternatively you can try the following Code: private void supprimerFil(String cdfl) {
Fil fl = ((Thread)sn.get(cdfl));
fl.deconnecterFil(elements, sn);
Intl srt = fl.getSortie();
sn.remove(cdfl);
/ / We delete isolated nodes
elmn();
updateGrilleTraces(); |
|
#4
| |||
| |||
| Re: Synchronize an iterator in java
Hello, What I mean Zekey is that during the course of a collection with an iterator, it is forbidden to modify the collection. This is not a timing issue but many multithreaded algorithm. Code: I am using a fl.remove (key) in the method supfl Code: clefsFils.remove(); |
|
#5
| |||
| |||
| Re: Synchronize an iterator in java
Hello, Thanks for the help, I have tried a code please check it and see if it is correct and if you find any problem in the code then guide me. here is the code: Code: private void supfl(cdfl String, Iterator clfl) {
Fil flsup = ((Thread)son.get(cdfl));
flsup.deconnecterFil(elements, son);
Intl srt = flsup.getSortie();
clfl.remove();
/ / We delete isolated nodes
eliminerNoeudsIsoles();
updateGrilleTraces();
} |
|
#6
| |||
| |||
| Re: Synchronize an iterator in java
Hello, I am new to this and even I am trying some programs on this, I have a small part of the code , which I have displayed here Code: synchronized(ls) {
Iterator i = ls.iterator(); // synchronized block
while (i.hasNext())
foo(i.next());
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Synchronize an iterator in java" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to check if the iterator points on an object in a list? | MAGALY | Software Development | 5 | 02-03-2010 07:59 PM |
| Designing LIFO and Iterator | Remedy | Software Development | 5 | 23-02-2010 05:57 AM |
| Iterator interface problem in an ArrayList | Ash maker | Software Development | 5 | 09-02-2010 06:06 AM |
| What is the difference between Iterator and Enumeration in Java? | Karsenman | Software Development | 4 | 28-01-2010 09:56 AM |
| How do you synchronize java? | Luis-Fernando | Software Development | 5 | 28-11-2009 06:07 PM |