Created
April 27, 2011 15:30
-
-
Save dfox/944478 to your computer and use it in GitHub Desktop.
A contrived asynchronous example class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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