Created
December 28, 2017 18:15
-
-
Save chathurangat/a4d3407f3d0e3c3cf70f02c4438f0346 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
import java.util.concurrent.*; | |
public class Application | |
{ | |
public static void main(String[] args) throws InterruptedException | |
{ | |
System.out.println("main thread is started"); | |
ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); | |
scheduledExecutorService.scheduleAtFixedRate(() -> { | |
System.out.println("Thread [" + Thread.currentThread().getName() + "] is executing the task"); | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { | |
System.out.println("sleeping thread get interrupted"); | |
} | |
}, 5, 2, TimeUnit.SECONDS); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment