1
00:00:00,330 --> 00:00:05,880
OK, now, instead of defining for individual threads, the task was to create an executor service with

2
00:00:05,880 --> 00:00:08,160
an appropriate number of active threads.

3
00:00:08,520 --> 00:00:14,370
By that, all I meant is we're going to use the formula for CPU bound tasks.

4
00:00:15,030 --> 00:00:17,100
So here, I'll say into a number of threads.

5
00:00:18,420 --> 00:00:24,120
And we're going to get the number of processors that our application has access to.

6
00:00:28,290 --> 00:00:30,630
And then we're going to use the executor service.

7
00:00:41,310 --> 00:00:46,410
To create a new fixed threat pool with this amount of threats.

8
00:00:48,600 --> 00:00:54,340
OK, now, instead of all this, we can just submit our tasks directly to the executor, executor,

9
00:00:54,440 --> 00:00:55,640
executors submit.

10
00:00:56,370 --> 00:00:57,990
We're going to submit this task.

11
00:01:01,850 --> 00:01:03,500
As well as the three other ones.

12
00:01:08,330 --> 00:01:10,010
Furniture technology.

13
00:01:11,690 --> 00:01:12,860
Office supplies.

14
00:01:14,500 --> 00:01:17,290
And it's total average.

15
00:01:21,520 --> 00:01:26,590
And the great thing about this is since we are submitting callable tasks, then our submit method is

16
00:01:26,590 --> 00:01:28,210
going to return a future object.

17
00:01:28,810 --> 00:01:29,830
So we'll say future.

18
00:01:31,860 --> 00:01:32,310
Double.

19
00:01:39,330 --> 00:01:41,610
And they have to import this first.

20
00:01:42,130 --> 00:01:42,440
OK.

21
00:01:43,170 --> 00:01:45,060
Copy and paste this three more times.

22
00:01:46,430 --> 00:01:49,940
Call this feature to Future three and future for.

23
00:01:52,140 --> 00:02:01,390
Now what we can do is as the thread is executing the callable task, the callable task is retaining

24
00:02:01,390 --> 00:02:04,990
that value and then we're going to use the future to get that value.

25
00:02:05,380 --> 00:02:12,010
So here we'll say, Oh, everything's already being done for us so we can go ahead and run the code.

26
00:02:17,910 --> 00:02:22,520
I forgot to shut down the executor, so here after everything has been done.

27
00:02:23,600 --> 00:02:26,480
We'll say executor that shut down.

28
00:02:34,520 --> 00:02:35,330
Controversy.

29
00:02:36,960 --> 00:02:38,070
We were in the application.

30
00:02:43,570 --> 00:02:44,080
Nice.

