Skip to content

Instantly share code, notes, and snippets.

@daniele-pecora
Created November 16, 2015 13:09
Show Gist options
  • Save daniele-pecora/8c7fd0e09cba9ed31829 to your computer and use it in GitHub Desktop.
Save daniele-pecora/8c7fd0e09cba9ed31829 to your computer and use it in GitHub Desktop.
Creating a concurrently running task with java
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