Thursday, 5 September 2013

Stop method on thread being called more than once?

Stop method on thread being called more than once?

The following method gets called in two different situations by two
different classes. Sometimes they both call it at the same time and I get
a ConcurrentModificationException.
I guess I could have a flag in the thread itself and check before running
thread.fadeOut()
But ideally I'd prefer stopAllPlaying() to fire only once, rather than
iterate over the array twice.
What's the best way to achieve this?
public void stopAllPlaying(int fadeDurationInMs)
{
for(PlayThread thread : threadMap.values()) {
if(thread != null) {
thread.fadeOut(fadeDurationInMs);
}
}
threadMap.clear();
}

No comments:

Post a Comment