Skip to content

Instantly share code, notes, and snippets.

@navopw
Last active May 24, 2016 19:07
Show Gist options
  • Save navopw/50ba592c11811c69008b01104b8334a8 to your computer and use it in GitHub Desktop.
Save navopw/50ba592c11811c69008b01104b8334a8 to your computer and use it in GitHub Desktop.
Java SingleThreadExecutor / Java 8 / Consumer-Style
Executor executor = Executors.newSingleThreadExecutor(); //Dein neuer Thread
//Beispielfunktion
public void getCoins(String uuid, Consumer<Integer> callback) {
executor.execute(() -> {
//Datenbankabfrage machen
//Wert im Consumer-callback zurückgeben
callback.accept(10);
});
}
//Beispiel Aufruf
databaseManager.getCoins("43a8afa8-b4fd-492d-b1a7-5a5d4da11d4f", (coins) -> {
System.out.println("Navo hat " + coins + " coins");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment