java - Execute code in the same method after Thread.join() executes -
i have problem, join
method, kill thread, not executing rest of method, started in thread. here code example:
private static thread thread; public static void addmessage(final string s) { thread = new thread() { @override public void run() { string data = message.send(s); addmessagetocontainer(data); } }; thread.start(); } public static void addmessagetocontainer(string data) { //do stuff data try { thread.join(); } catch (interruptedexception e) { e.printstacktrace(); } //this code here not executed. }
so normally, of course can execute code before call join
function. have load after thread execution webview content. when remove join
, give me following error message:
java.lang.runtimeexception: java.lang.throwable: webview method called on thread 'thread-9072'. webview methods must called on same thread. (expected looper looper (main, tid 1) {5ac9b39} called on null, fyi main looper looper (main, tid 1) {5ac9b39})
so can load content after thread has executed?
join doesn't kill thread. join waits until thread kills itself. code executed- @ time in future, when thread decides done. calling wait on thread thread cause deadlock , never anything, yet never die. in case above you're calling thread itself, hang forever.
there no way kill thread directly, because impossible safely. way kill thread outside interrupt it, , let thread check if isinterrupted() every , if kill itself. way kill thread inside return runnable's run method.
your webview error totally unrelated. can touch views on main thread. don't webview on thread.
Comments
Post a Comment