Skip to content

Instantly share code, notes, and snippets.

@dfox
Created April 27, 2011 15:30
Show Gist options
  • Save dfox/944478 to your computer and use it in GitHub Desktop.
Save dfox/944478 to your computer and use it in GitHub Desktop.
A contrived asynchronous example class
public interface Callback {
void completed();
}
public class AsynchronousTask extends Thread {
private Callback callback;
private int result;
public AsynchronousTask(final Callback callback){
this.callback = callback;
}
@Override
public void run() {
try {
//Do some "work"
sleep(5);
result = 42;
}
catch (InterruptedException ex) { }
callback.completed();
}
public int getResult() {
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment