[BAEL-7073] delete code from old module

This commit is contained in:
uzma 2023-12-17 16:44:23 +00:00
parent efb0046025
commit ee4679456f
2 changed files with 0 additions and 55 deletions

View File

@ -1,24 +0,0 @@
package com.baeldung.concurrent.executorservice;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ExecuteExample {
public static void main(String[] args) {
ExecutorService executorService = Executors.newFixedThreadPool(2);
// Task using Runnable
Runnable task = () -> {
int[] numbers = { 1, 2, 3, 4, 5 };
int sum = 0;
for (int num : numbers) {
sum += num;
}
System.out.println("Sum calculated using execute:" + sum);
};
// Submit the task using execute
executorService.execute(task);
executorService.shutdown();
}
}

View File

@ -1,31 +0,0 @@
package com.baeldung.concurrent.executorservice;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class SubmitExample {
public static void main(String[] args) {
ExecutorService executorService = Executors.newFixedThreadPool(2);
Callable<Integer> task = () -> {
int[] numbers = { 1, 2, 3, 4, 5 };
int sum = 0;
for (int num : numbers) {
sum += num;
}
return sum;
};
// Submit the task and obtain a Future
Future<Integer> result = executorService.submit(task);
try {
// Get the result
int sum = result.get();
System.out.println("Sum calculated using submit:" + sum);
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
executorService.shutdown();
}
}