How to stop a thread running through TaskExecutor from the main thread after it doesnt respond in few seconds?
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Generally speaking, you don't do that. If you want the HTTP request to stop after hanging for a while, then set a timeout on it. It's always best to let the thread finish whatever work it's been given to do. Edit: Based on your source code, the first thing you need to do is make sure to call connect() on the URLConnection. Otherwise, nothing will happen. Take a look at Working with URLs in the Java Tutorial. After that, if you still want to set timeouts, use setConnectTimeout() to set the amount of time it should try to connect before timing out and setReadTimeout() to set the amount of time it should wait to receive data after a request is sent.
|
create thread from other thread throw exception like Can't create handler inside thread that has not called Looper.prepa
Date : March 29 2020, 07:55 AM
I wish this helpful for you You are doing many things in other thread, then should be event thread, like toast displaying, dismissing dialog, please place your code which need to be in Event thread, in event thread by using either Handler, or Asynctask.
|
Thread inside thread: what happens if parent thread is killed?
Tag : java , By : Thomas Gueze
Date : March 29 2020, 07:55 AM
hope this fix your issue From docs Thread
|
Behavior of Thread B spawned inside Thread A when Thread A dies
Date : March 29 2020, 07:55 AM
around this issue Simple solution: change doAction() to return that thread it is creating; so that the calling code can call start() on that Thread; like this: public Thread doAction(){
Thread insideThread = new Thread(() -> {
//do something
});
return insideThread;
}
|
Can't create handler inside thread Thread[Thread-5,5,main] that has not called Looper.prepare()
Tag : java , By : CHeMoTaCTiC
Date : March 29 2020, 07:55 AM
should help you out What does the following exception mean; how can I fix it? This is the code: , Inside your onResponse show your dialog like below inside a UI thread activity.runOnUiThread(new Runnable() {
public void run() {
new AlertDialog.Builder(mcontext)
.setTitle("titleļ¼")
.setMessage(TmpPwd)
.setPositiveButton("close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.show();
}
});
|