java run code at interval

Solutions on MaxInterview for java run code at interval by the best coders in the world

showing results for - "java run code at interval"
Layla
07 May 2016
1   /* Perform this runnable code every 5 seconds  in this example*/
2   Runnable runnable = new Runnable() {
3			public void run() {
4				// task to run goes here
5				System.out.println("Hello !!");
6			}
7		};
8		ScheduledExecutorService service = Executors
9				.newSingleThreadScheduledExecutor();
10		service.scheduleAtFixedRate(runnable, 0, 5, TimeUnit.SECONDS);