Skip to content

Instantly share code, notes, and snippets.

@daniele-pecora
Created November 16, 2015 13:09
Show Gist options
  • Select an option

  • Save daniele-pecora/8c7fd0e09cba9ed31829 to your computer and use it in GitHub Desktop.

Select an option

Save daniele-pecora/8c7fd0e09cba9ed31829 to your computer and use it in GitHub Desktop.

Revisions

  1. Daniele Pecora renamed this gist Nov 16, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt → MyConcurrentJob.java
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    /**
    * Using javas {@link java.util.concurrent.ExecutorService ExecutorService} to run an action concurrently
    */
    public class MyJob{
    public class MyConcurrentJob{

    public void justDoIt(){
    Runnable action = () -> {
  2. Daniele Pecora created this gist Nov 16, 2015.
    19 changes: 19 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    import java.util.concurrent.Executors;
    /**
    * Using javas {@link java.util.concurrent.ExecutorService ExecutorService} to run an action concurrently
    */
    public class MyJob{

    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);
    }

    }