JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

Showing posts with label ScheduledThreadPoolExecutor. Show all posts
Showing posts with label ScheduledThreadPoolExecutor. Show all posts

Java ScheduledThreadPoolExecutor Example

8:17 AM
There are multiple ways to schedule a task in java. We have already  Java timer  to schedule a task but the problem with timers task is that you can execute one task at a time.So if the current task takes longer subsequent job will be delayed. In this scenario, you can use Java ScheduledThreadPoolExecutor.This class is a part of Executor framework and provides facility to schedule a task rather than executing it immediately. There are three methods which you can use to schedule task using ScheduledThreadPoolExecutor. schedule scheduleAtFixedRate scheduleWithFixedDelay Java ScheduledThreadPoolExecutor Example: Step 1: Create a Runnable task named “RunnableTask.java”. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31   package org . arpit . java2blog ;   import java . util . Date ;   public class RunnableTask implements Runnable {   pr

.