-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample3.java
More file actions
27 lines (25 loc) · 906 Bytes
/
Example3.java
File metadata and controls
27 lines (25 loc) · 906 Bytes
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
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
//Programacion asincrona con Thread pool
public class Example3 {
public static void main(String[] args) throws InterruptedException {
ExecutorService service = Executors.newFixedThreadPool(2);
for(int count = 0; count < 5; count++){
service.execute(()->{
try {
Thread.sleep(3000);
} catch (InterruptedException e) {}
System.out.println("Sub Thread " + Thread.currentThread().getName());
});
}
service.shutdown();
synchronousTask2();
}
public static void synchronousTask1() throws InterruptedException {
System.out.println("Obtuve datos");
Thread.sleep(10000);
}
public static void synchronousTask2(){
System.out.println("Calcular IVA");
}
}