Yes your callback will run as long as the process is still alive.
If you want to see I created a program to simulate just that. It has three classes just drop them in any one package and run and you will see your self. This depicts even when your job thread completes callback still comes.
I hope it helps :)
Class 1
public class Client {
private static long startTime = System.currentTimeMillis();
public static void main(String[] args) {
System.out.println("Time elapsed in ms:" + (System.currentTimeMillis() - startTime));
Client client = new Client();
client.executeJob();
try {
System.out.println("Main thread sleeping");
Thread.sleep(20000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Main thread finishing");
}
public void executeJob() {
new Thread() {
@Override
public void run() {
Job job = new Job();
System.out.println("Calling Job with Asyc - Time elapsed in ms:"
+ (System.currentTimeMillis() - startTime));
job.doRequest("Calling Async", new CallBack() {
@Override
public void onRequestComplete(String response) {
System.out.println("Got my callback eventhough job that started the Async is over - Time elapsed in ms:"
+ (System.currentTimeMillis() - startTime));
}
});
System.out.println("Job thread finishing");
}
}.start();
}
}
Class 2
public abstract class CallBack {
public abstract void onRequestComplete(String response);
}
Class 3
public class Job {
public void doRequest(String request, final CallBack callBack){
new Thread() {
@Override
public void run() {
//Async Long running task
try {
Thread.sleep(10000);
callBack.onRequestComplete("Long Async task Completed-- Sending response back");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
}
}