-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaysToImplement3.java
More file actions
34 lines (27 loc) · 1.24 KB
/
WaysToImplement3.java
File metadata and controls
34 lines (27 loc) · 1.24 KB
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
32
33
34
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class WaysToImplement3 {
public static void main(String[] args) {
//3. Using ScheduledExecutorService (Scheduled Tasks)
//Allows executing tasks after a delay or at fixed intervals.
//Useful for running cron jobs and monitoring!
// Runnable run = new Runnable() {
// @Override
// public void run(){
// System.out.println("Scheduled Task Executed at: " + System.currentTimeMillis());
// }
// };
Runnable run = () -> {
// System.out.println("Scheduled Task Executed at: " + System.currentTimeMillis());
System.out.println("Current Time: " + new Date());
};
ScheduledExecutorService executer = Executors.newScheduledThreadPool(3);
executer.scheduleAtFixedRate(run, 1, 1 , TimeUnit.SECONDS);
//4. Using ForkJoinPool (Parallel Processing)
//Suitable for divide-and-conquer tasks, used in parallel computing.
//Used for parallel processing (e.g., image processing, big data computations).
//to be continued...
}
}