Thread & Semaphors

Here are some links about threads and synchronization:
Using Threads in J2ME Applications:http://wireless.java.sun.com/midp/articles/threading2/
The Java™ FAQ – Threads:http://java.sun.com/docs/books/faq/faqthr.html

There are several books on the subject. Go to amazon and search for java treads.

[quote]So you mean that if I make m = Collections.synchronizedMap(writeQeue); m will always have the same content as writeQeue?
[/quote]
Kind of. m is an interface to your original writeQueue object. It do not store any data in itself. It has a referance to your writeQueue and it calls the respective function on your writeQueue. In addition it makes sure that only one thread is allowed to use writeQueue at a time, using this interface object.

So all methods I would call on writeQeue I should call on m now? like .get() and .put() ?

yes

ok thanks Ill work on it :slight_smile:

You can’t do this in the loop, it modifies the collection you are iterating over… think about it… connect the dots…

writeQeue.remove(key); 

Make a COPY of the keys… iterate over the copy… Or (better) make a new collection of the objects you intend to remove, then remove them in a separate loop after you have all of them.

Yeah I noticed this as well, but wasnt really sure :slight_smile: Thanks!