java - IllegalThreadStateException: Thread already started on a new Thread -
i have android app published in play store, , crashreports show fatal exception: java.lang.illegalthreadstateexception: thread started in
public void refresh(){ if (thread.currentthread() != mthread) { mthread = new thread() { @override public void run() { refresh(); } }; mthread.start();//<<<<<<<<<<<<<here return; } dosomecoolstuff(); }
how can happen? new thread?
metin kale
this can happen in case of race condition. between 2 statements (assigning value mthread , calling start() method), execution can switch thread, can enter refresh() method again, assign different thread mthread, , start it. when first thread resumes execution, mthread contain different thread (which has been started), , start() method fail exception describe.
one way fix store result of new thread()
in local variable, call start() method on variable, , save field. (this may not appropriate fix, it's not possible more without knowing more details context problem happens.)
Comments
Post a Comment