HashMap ConcurrentModificationException

Я не могу понять, почему я получаю ConcurrentModificationException в моем «цикле очистки».

private HashMap<String, Long> firsthits = new HashMap<String, Long>();

public void addHit(String name) {
    firsthits.put(name, System.currentTimeMillis());

    if (firsthits.size() > 5) {
        for(Iterator<Map.Entry<String, Long>> it = firsthits.entrySet().iterator(); it.hasNext(); ) {

            Map.Entry<String, Long> s = it.next();

            if ( (s.getValue() + 15000) < System.currentTimeMillis() ) {
                firsthits.remove(s.getKey());
            }
        }
    }
}

Я пробовал и многие другие петли. И это на 100% синхронизация, никакие другие потоки не касаются первыми.

Ошибка указывает на строку № 14: if (firsthits.size ()> 5) {

Вот исключение:

Caused by: java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:839) ~[?:1.7.0_67]
at java.util.HashMap$EntryIterator.next(HashMap.java:880) ~[?:1.7.0_67]
at java.util.HashMap$EntryIterator.next(HashMap.java:878) ~[?:1.7.0_67]

person TacoB    schedule 08.12.2014    source источник
comment
Ой, я тупой, я удалял из хэш-карты, а не из итератора .. Мои негодяи :(   -  person TacoB    schedule 08.12.2014