Last active
May 24, 2016 19:07
-
-
Save navopw/50ba592c11811c69008b01104b8334a8 to your computer and use it in GitHub Desktop.
Java SingleThreadExecutor / Java 8 / Consumer-Style
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
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