Skip to content

Instantly share code, notes, and snippets.

@chathurangat
Created December 28, 2017 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chathurangat/a4d3407f3d0e3c3cf70f02c4438f0346 to your computer and use it in GitHub Desktop.
Save chathurangat/a4d3407f3d0e3c3cf70f02c4438f0346 to your computer and use it in GitHub Desktop.
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