java - ConcurrentModificationError - but no modifications? -


i have piece of code:

public static final reentrantlock lock = new reentrantlock();  public static void sendmessage(final arraylist<string> jids, final string text) {     synchronized (mainactivity.getcontext()) {         if (jids != null) {             lock.lock();             try {                 runnable r = new runnable() {                     public void run() {                         if (looper.mylooper() == null) {looper.prepare();}                         (string jid : jids) {                             if (jid != null) {                                 intent sendintent = new intent();                                 sendintent.setaction("message.platform.send_message");                                 sendintent.putextra("jid", jid);                                 sendintent.putextra("content", text);                                 mainactivity.getcontext().sendbroadcast(sendintent);                             }                             try {                                 thread.sleep(300);                             } catch (interruptedexception e) {                                 e.printstacktrace();                             }                         }                     }                 };                 thread t = new thread(r);                 t.start();                 try {t.join();} catch (interruptedexception e) {e.printstacktrace();}             } {                 lock.unlock();             }         }     } } 

what it's supposed iterate on list of different jid's , send them each same message 300ms delay in between each message. process has synchronized , locked, because don't want multiple threads accessing code @ same time. runs on thread while executing code because of needed 300ms delay (don't want on ui).

however, after multiple hours of running code successfully, goes wrong error:

java.util.concurrentmodificationexception @ java.util.arraylist$arraylistiterator.next(arraylist.java:573) 

and points @ piece of code in method:

>>> (string jid : jids) { 

as far concerned not modifying list in way shape or form... going on? , why work hours , randomly spit out error? in advance!

edit:

i call method so:

sendmessage(new arraylist<string>(arrays.aslist("jid1","jid2")),"hello everyone!"); 


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -