Created
December 29, 2018 08:22
-
-
Save damithadayananda/6ce8409c7dbdffff15931b6b01baff90 to your computer and use it in GitHub Desktop.
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
package taskExecutor; | |
import java.util.concurrent.TimeUnit; | |
public class Task implements Runnable { | |
private String name; | |
public Task(String name){ | |
this.name = name; | |
} | |
public String getName(){ | |
return name; | |
} | |
@Override | |
public void run() { | |
try{ | |
Long duration = (long)(Math.random()*10); | |
System.out.println("Doing a task during : " + name); | |
TimeUnit.SECONDS.sleep(duration); | |
}catch (InterruptedException e){ | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment