I need to understand how threads run inside methods, for example if I do this
Thread is executed and everything is OK
Private Zero Certain Methods () {myThread obj = new myThread (); Obj.start (); } Private class extension of myThread thread {@Overrride Public Zero Run ()} {// action}; }
But if I do this then it was triggered at the last (after callAnthEpment and that random variable declaration) even though I have called the thread first
Private Zero Some Method () {myThread obj = new myThread (); Obj.start (); CallAnotherMethod (); String some variables = ""; } Private class extension of myThread thread {@Overrride Public Zero Run ()} {// action}; }
My problem is that I need to create somethings in the thread to use in my methods, but if I write the code like this, then my thread is triggered for the last time How could I use my thread first and then use other methods?
You can use callable and future classes Are there. A callable thread, which once works, gives a future object. You can wait for the future to be available. See examples from JavaDoc -
No comments:
Post a Comment