multithreading - Android Thread Safety; Data Injection into a thread -


i have created example:

import static java.lang.thread.sleep;  public class example implements runnable, iexternal {      object o = null;     // construstor parameters thread     example(object o){          this.flag = (boolean)o;          controller.iextofexample = (iexternal) this;     }      volatile boolean flag = true;     object p1, p2 = null;     public volatile string result= "";      @override     public void run() {         while (flag){             try {                 sleep(1000);             } catch (interruptedexception e) {                 e.printstacktrace();             }             // code             result = p1.tostring() + p2.tostring();         }      }      @override     public void reset() {         flag = false;     }      @override     public boolean methodb(object o1, object o2) {         p1 = o1; p2 = o2;         return true;     } }  interface iexternal{     void reset();     boolean methodb(object o1, object o2); }  class controller {     public static iexternal iextofexample = null; }  //from somewhere..  class mainapp{      void method(){         example ex = new example(true);         try {             thread example = new thread(ex);             example.start ();         } catch (exception e) {             e.printstacktrace ( );         }         // thread safe?         //         controller.iextofexample.methodb("parameter 1", "parameter 2");         string ret = ex.result;         controller.iextofexample.reset();         // or         ex.methodb("parameter 1", "parameter 2");         ret = ex.result;         ex.reset();     } } 

is thread compartment term available in android java?

when start thread, part of code placed thread compartment : method run or whole object of treadable class?

how inject data inside tread safely : using interface or using pointer class' object?


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -