Created
November 16, 2015 13:09
-
-
Save daniele-pecora/8c7fd0e09cba9ed31829 to your computer and use it in GitHub Desktop.
Creating a concurrently running task with java
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
import java.util.concurrent.Executors; | |
/** | |
* Using javas {@link java.util.concurrent.ExecutorService ExecutorService} to run an action concurrently | |
*/ | |
public class MyConcurrentJob{ | |
public void justDoIt(){ | |
Runnable action = () -> { | |
try { | |
// do whatever you like to do here... | |
System.out.println("I'm doing somethin' concurrently..."); | |
} catch (Exception e) { | |
e.printStacktrace(); | |
} | |
}; | |
Executors.newSingleThreadExecutor().execute(action); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment