DS
Size: a a a
DS
Y
DS
Y
d
d
d
d
Y
Y
ExecutorService executorService = Executors.newSingleThreadExecutor();Ну по такому примеру очень понятно
Future<String> future = executorService.submit(() -> {
Thread.sleep(2000);
return "Hello from Callable";
});
while(!future.isDone()) {
System.out.println("Task is still not done...");
Thread.sleep(200);
}
System.out.println("Task completed! Retrieving the result");
String result = future.get();
System.out.println(result);
executorService.shutdown();
G
Y
DS
Y
Runnable r = () -> {
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
};
Callable<String> callable = () -> {
// Perform some computation
new Thread(r).start();
Thread.sleep(1000);
return "Hello from Callable";
};
DS
Runnable r = () -> {
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
};
Callable<String> callable = () -> {
// Perform some computation
new Thread(r).start();
Thread.sleep(1000);
return "Hello from Callable";
};
Y
Y
DS
Y