Here is my Thread:-
Thread t=new Thread(){
public void run(){
downloadFile();
}
}
t.start();
public static void main(){
t.interrupt();
}
Here downloadFile()
is long running method (downloading file from server)
The issue is , even though t.interrupt()
is called downloadFile() method still keeps running which is not expected . I want downloadFile() method to terminate immediately as soon as the thread is interrupted. How should i achieve it ?
Thanks.
EDIT1:
Here is downloadFile() skeleton which calls the rest API to fetch file:
void downloadFile(){
String url="https//:fileserver/getFile"
//code to getFile method
}