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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1
00:00:06,000 --> 00:00:06,000
Hello.

2
00:00:06,000 --> 00:00:12,000
There are students in this lesson, we'll learn implementations of executive service interface and parents

3
00:00:12,000 --> 00:00:12,000
lessons.

4
00:00:12,000 --> 00:00:19,000
We learned what executive interface is and what executive service interface is to show them.

5
00:00:19,000 --> 00:00:25,000
I had to use one implementation of executive service that today will require different implementations

6
00:00:25,000 --> 00:00:31,000
of this interface and different use cases so that you'll know when to use one specific implementation.

7
00:00:32,000 --> 00:00:38,000
Today will review fix reticule executer cash, streetball, single streetball, shadowless reticule.

8
00:00:39,000 --> 00:00:41,000
As we will go over each executer one by one.

9
00:00:41,000 --> 00:00:48,000
I will also explain what threat factor is and how you can use it during the installation of threats.

10
00:00:48,000 --> 00:00:54,000
You understand what a threat starvation is and how to calculate a perfect number of threats for your

11
00:00:54,000 --> 00:00:55,000
threat pool.

12
00:00:55,000 --> 00:01:00,000
I'm going to show you formulas and we'll teach you how to calculate the blocking coefficient.

13
00:01:01,000 --> 00:01:04,000
And as always, we are going to have a lot of examples to the source.

14
00:01:04,000 --> 00:01:08,000
Code of all examples is in attachment to this lesson.

15
00:01:08,000 --> 00:01:10,000
Let's start today.

16
00:01:10,000 --> 00:01:14,000
We'll learn with you everything from official documentation and the code examples.

17
00:01:14,000 --> 00:01:16,000
So let me start screen sharing.

18
00:01:17,000 --> 00:01:19,000
I open source code of executor's class.

19
00:01:20,000 --> 00:01:25,000
I believe you remember that we have factory mascots in this class that allows us to create instances

20
00:01:25,000 --> 00:01:31,000
of different implementations of executive service interface and considerable amount of this factory

21
00:01:31,000 --> 00:01:33,000
masses and level of details.

22
00:01:33,000 --> 00:01:39,000
I would like to focus your attention on the difference between all of them and the main features rather

23
00:01:39,000 --> 00:01:41,000
than on the source code of each particular executer.

24
00:01:42,000 --> 00:01:43,000
So let's go one by one.

25
00:01:44,000 --> 00:01:47,000
We will start from the top from the first factory mass.

26
00:01:48,000 --> 00:01:53,000
This method is called new fixed thread pool and takes in value as method argument.

27
00:01:54,000 --> 00:01:57,000
You can see that we reach an object of streetball executive type.

28
00:01:58,000 --> 00:01:59,000
Let me open this one.

29
00:01:59,000 --> 00:02:07,000
SWEPCO executive type extends Abstract Executive Service Zissis abstract class that is used by different

30
00:02:07,000 --> 00:02:14,000
implementations of executive service, the common implementations of some methods that are appropriate

31
00:02:14,000 --> 00:02:18,000
for all concrete classes that extends this abasic one.

32
00:02:18,000 --> 00:02:25,000
And as you can see, abstract executive service implements executive service, which in turn implements

33
00:02:25,000 --> 00:02:29,000
executer hope that the Iraqi is clear for you.

34
00:02:29,000 --> 00:02:33,000
It will be similar for other executor's for our lesson today.

35
00:02:34,000 --> 00:02:36,000
Let's now get back to Executor's.

36
00:02:36,000 --> 00:02:44,000
So this massive new streetball grades and executive service that we use as fixed number of threats,

37
00:02:44,000 --> 00:02:48,000
the fixed number of threats is passed to the method as methods argument.

38
00:02:49,000 --> 00:02:50,000
The idea is simple.

39
00:02:50,000 --> 00:02:56,000
All threats work on tasks in parallel, depending on your computer characteristics.

40
00:02:56,000 --> 00:03:03,000
The number of threads running simultaneously and in parallel is different in case the more tasks than

41
00:03:03,000 --> 00:03:10,000
current threats available to execute those tasks will wait in the queue until any threat from the pool

42
00:03:10,000 --> 00:03:11,000
will be available again.

43
00:03:11,000 --> 00:03:17,000
What will happen in case any other threats will be terminated because of the failure during the execution,

44
00:03:18,000 --> 00:03:22,000
new one will be created and take its place to execute subsequent tasks.

45
00:03:22,000 --> 00:03:24,000
Let's look at the example now.

46
00:03:24,000 --> 00:03:30,000
I open the fixed thread, pull them across all executer examples that I will show you today.

47
00:03:30,000 --> 00:03:38,000
Located in executor's package, you can find a link to the package was all executor's examples in attachments

48
00:03:38,000 --> 00:03:39,000
to this lesson.

49
00:03:39,000 --> 00:03:44,000
I create my Reppel executer, pay attention and create a pool for three threats.

50
00:03:45,000 --> 00:03:51,000
Also, you can see that I cost object here because factoring in massive new fixed rate pool declares

51
00:03:51,000 --> 00:03:58,000
that executive service will be returned and recommends us to operate with objects on this abstraction

52
00:03:58,000 --> 00:03:58,000
level.

53
00:03:59,000 --> 00:04:03,000
But we know that this concrete implementation of executive service will be used.

54
00:04:04,000 --> 00:04:09,000
I need this to show your class specific matters that are absent in executive service.

55
00:04:09,000 --> 00:04:13,000
After that, I submit for similar tasks to the executive service.

56
00:04:14,000 --> 00:04:17,000
Each task sleep for one second and that's it.

57
00:04:18,000 --> 00:04:24,000
I need the sleep for the sake of example, I call shut down MassArt here to not allow anyone to submit

58
00:04:24,000 --> 00:04:28,000
any other tasks to this executive service after this line.

59
00:04:29,000 --> 00:04:32,000
After that I principle size and Q's size.

60
00:04:32,000 --> 00:04:39,000
These are class specific masses that are absent in executive service, but that will allow us to show

61
00:04:39,000 --> 00:04:41,000
the future of fixed threat pool.

62
00:04:41,000 --> 00:04:42,000
Let me run the program.

63
00:04:43,000 --> 00:04:47,000
I run the program and I can see that pool size is three.

64
00:04:47,000 --> 00:04:50,000
The number of threats that I have in my pool.

65
00:04:50,000 --> 00:04:56,000
I passed this number to the factory Masset and number of tasks in queue is one.

66
00:04:56,000 --> 00:05:02,000
That is because each task sleeps one second and the fourth task has no threats that would.

67
00:05:03,000 --> 00:05:09,000
I said that's why it is in queue for the execution, but once these tasks are finished, one of the

68
00:05:09,000 --> 00:05:11,000
threats is the last one.

69
00:05:12,000 --> 00:05:15,000
Once all tasks are processed, UVM is finished.

70
00:05:16,000 --> 00:05:20,000
That is because I call shut down MassArt, imperfect world.

71
00:05:20,000 --> 00:05:26,000
I should call every termination Hendel potential interrupted exception and call shut down now.

72
00:05:26,000 --> 00:05:32,000
But we discussed this in previous lesson and to not write a lot of code that doesn't directly relate

73
00:05:32,000 --> 00:05:34,000
to the topic today, I will skip it.

74
00:05:34,000 --> 00:05:40,000
But please make sure you learned well previous lesson and you know how to terminate multiple threats.

75
00:05:40,000 --> 00:05:46,000
With the help of executive service, my students often ask me how to define ideal number of threats

76
00:05:46,000 --> 00:05:48,000
to create infix threat pool.

77
00:05:49,000 --> 00:05:54,000
I mean, what criteria we should use to define whether we need to create four, eight or chanceries

78
00:05:54,000 --> 00:05:55,000
in pool.

79
00:05:56,000 --> 00:06:02,000
It is not an easy question, but I will try explain it as simple as possible before calculating perfect

80
00:06:02,000 --> 00:06:03,000
number of threats.

81
00:06:03,000 --> 00:06:05,000
You should understand your limits.

82
00:06:05,000 --> 00:06:09,000
And I'm talking not only about a number of CPU's in your computer.

83
00:06:10,000 --> 00:06:12,000
I also want to draw attention to other limits.

84
00:06:13,000 --> 00:06:17,000
For example, Zamunda limit on number of connections to a database.

85
00:06:17,000 --> 00:06:23,000
Does it make sense to have one hundred twines threats that interact with database and have limited database

86
00:06:23,000 --> 00:06:25,000
connection with ten connections?

87
00:06:25,000 --> 00:06:27,000
Only the answer is obvious.

88
00:06:28,000 --> 00:06:34,000
Or if a threat interacts with other system and sends a request to the APIs that can produce only a few

89
00:06:34,000 --> 00:06:35,000
requests simultaneously.

90
00:06:36,000 --> 00:06:43,000
This fact also needs to be considered because in the most pessimistic case, we may end up with reservation

91
00:06:43,000 --> 00:06:45,000
state or even without of memory error.

92
00:06:46,000 --> 00:06:47,000
What a threat.

93
00:06:47,000 --> 00:06:47,000
Starvation.

94
00:06:48,000 --> 00:06:54,000
Starvation describes a situation where Sweat is unable to gain regular access to shared resources and

95
00:06:54,000 --> 00:06:56,000
is unable to make progress.

96
00:06:56,000 --> 00:07:02,000
This happens when shared resources are made unavailable for long periods of grief threats.

97
00:07:02,000 --> 00:07:07,000
And of course, another important factor to consider is number of years.

98
00:07:07,000 --> 00:07:13,000
You can identify a number of tips like this call runtime static MassArt on runtime Closs.

99
00:07:14,000 --> 00:07:20,000
You would get the reference to the runtime object and invoke available processers you will get enough

100
00:07:20,000 --> 00:07:21,000
value.

101
00:07:21,000 --> 00:07:24,000
This would be the number, of course, on your computer.

102
00:07:24,000 --> 00:07:31,000
Be careful with this massive one you will work with container's this approach might provide it was wrong

103
00:07:31,000 --> 00:07:34,000
information without any specific constraints.

104
00:07:34,000 --> 00:07:41,000
A continuous process will be able to see the hardware on the operating system and it might happen at

105
00:07:41,000 --> 00:07:43,000
your containerised application.

106
00:07:43,000 --> 00:07:48,000
Supposedly is too coarse only, but your operating system has eight.

107
00:07:48,000 --> 00:07:52,000
So just be careful when you rely on this value.

108
00:07:52,000 --> 00:07:59,000
Here we have another variable executive service, too, and I want to show you that you can initialised

109
00:07:59,000 --> 00:08:04,000
your executive service just like this in one line by passing the number, of course, to the masses.

110
00:08:05,000 --> 00:08:11,000
But still, I mentioned the different factors that would impact our decision and that will help us to

111
00:08:11,000 --> 00:08:13,000
answer what is a growing number of threats.

112
00:08:13,000 --> 00:08:15,000
And it took great in my streetball.

113
00:08:15,000 --> 00:08:19,000
Let's review a formula from book Java Concurrency.

114
00:08:19,000 --> 00:08:25,000
In practice, number of threads equal to the number of available course multiplied by the result of

115
00:08:25,000 --> 00:08:30,000
the next expression one plus the result of division between the wait time and service time.

116
00:08:31,000 --> 00:08:34,000
Don't worry, it is not so scary as it looks like.

117
00:08:34,000 --> 00:08:41,000
And the first glance, let's review it in detail and we need to understand first what is the wait time

118
00:08:41,000 --> 00:08:42,000
and what is a service?

119
00:08:42,000 --> 00:08:49,000
Time wasting time is a time spent waiting for inputs and outputs bound tasks to complete.

120
00:08:49,000 --> 00:08:55,000
For example, this is not the amount of time you're waiting for a response from remote server.

121
00:08:56,000 --> 00:09:03,000
And this is just one example because it might be not only input output tasks, but any tasks that makes

122
00:09:03,000 --> 00:09:09,000
execution wait for some event and as examples might be getting monitor log.

123
00:09:09,000 --> 00:09:10,000
What is service time?

124
00:09:11,000 --> 00:09:13,000
Service time is a useful time.

125
00:09:13,000 --> 00:09:21,000
The time spent being busy, for example, process HTP, response, data filtering or transformation,

126
00:09:21,000 --> 00:09:27,000
etc. So dividing the waiting time by service time will get the result that is often called blocking

127
00:09:27,000 --> 00:09:32,000
coefficient, a computation intensive task Hasbrouck and coefficient close to zero.

128
00:09:33,000 --> 00:09:39,000
Now let's assume that we have four CPUs and let's substitute numbers in the formula with your data and

129
00:09:39,000 --> 00:09:41,000
zero for blocking creation.

130
00:09:42,000 --> 00:09:44,000
What result you have in this case?

131
00:09:44,000 --> 00:09:47,000
The number of threads is equal to the number of available course.

132
00:09:47,000 --> 00:09:52,000
If all tasks are computation intensive, then this is all we need.

133
00:09:52,000 --> 00:09:59,000
And having more threats won't help us to improve performance because we respect the restriction of having

134
00:09:59,000 --> 00:10:01,000
a limited number of CPUs.

135
00:10:02,000 --> 00:10:03,000
Now, let's give you another example.

136
00:10:04,000 --> 00:10:09,000
Imagine that our application process, different amount of data that is read from the server in the

137
00:10:09,000 --> 00:10:12,000
Internet, you just send the request.

138
00:10:12,000 --> 00:10:19,000
And the way the response was, the data program reads a bunch of data and processes it after that program,

139
00:10:19,000 --> 00:10:26,000
reads another batch of data and processes it again, having the performance benchmark evaluation.

140
00:10:26,000 --> 00:10:32,000
You know, that process of reviewing one batch takes two hundred milliseconds, for example, and time

141
00:10:32,000 --> 00:10:33,000
of processing of this data.

142
00:10:34,000 --> 00:10:35,000
Take 20 milliseconds.

143
00:10:36,000 --> 00:10:38,000
Let's substitute numbers in our formula.

144
00:10:39,000 --> 00:10:43,000
And in this case, following calculations in formula, we need forty four sets.

145
00:10:44,000 --> 00:10:46,000
It seems to be a big amount of threats.

146
00:10:46,000 --> 00:10:48,000
Let's think about it from another point of view.

147
00:10:49,000 --> 00:10:55,000
You're going to have tasks that will be blocked waiting for two hundred milliseconds and what these

148
00:10:55,000 --> 00:10:58,000
threats should do, just sitting and waiting.

149
00:10:58,000 --> 00:11:02,000
They're doing exactly this thing, sitting and waiting.

150
00:11:02,000 --> 00:11:08,000
And in the meantime, we have processors that are ready and happy to execute any other computations.

151
00:11:09,000 --> 00:11:14,000
That's why in this particular case, with such weighting and service time, it is reasonable to have

152
00:11:14,000 --> 00:11:17,000
44 phosphorescence a fixed rate pool.

153
00:11:17,000 --> 00:11:22,000
There is a good practice to have separate executive services for each set of tasks.

154
00:11:22,000 --> 00:11:28,000
In this case, each executive service may be configured accordingly for a specific class of tasks,

155
00:11:29,000 --> 00:11:31,000
and one would have multiple executive services.

156
00:11:31,000 --> 00:11:36,000
We need to adjust our formula by adding CPU utilization parameter to it.

157
00:11:37,000 --> 00:11:37,000
What?

158
00:11:37,000 --> 00:11:45,000
Well, you may be in target CPU utilization variable from zero to one inclusively where zero means that

159
00:11:45,000 --> 00:11:52,000
streetball want to use processors at all and one means that streetball will use one hundred percent

160
00:11:52,000 --> 00:11:53,000
of processors for time.

161
00:11:54,000 --> 00:11:56,000
The formula becomes localizes.

162
00:11:57,000 --> 00:12:04,000
In the similar case, and if I plan to grant only 50 percent of processers time to the batch data processing

163
00:12:04,000 --> 00:12:11,000
and another 50 percent will be dedicated to other activities or other executive service, we are going

164
00:12:11,000 --> 00:12:12,000
to have another result.

165
00:12:13,000 --> 00:12:20,000
I add a zero point five to reflect targeted utilization and as a result, we have twenty two threats.

166
00:12:20,000 --> 00:12:26,000
This number of threats you need to create in streetball to be efficient with these group of tasks.

167
00:12:27,000 --> 00:12:33,000
Definitely life cases are different and it is not always so easy to calculate weighting and service

168
00:12:33,000 --> 00:12:35,000
time for each task that you are going to create.

169
00:12:36,000 --> 00:12:42,000
That's why these formulas are just a great starting point for you and hope that these formulas will

170
00:12:42,000 --> 00:12:47,000
help you to understand the motivation to make a final decision regarding a number of threads in the

171
00:12:47,000 --> 00:12:48,000
thread.

172
00:12:49,000 --> 00:12:54,000
OK, now when you know, let's get back to Demo New Fix.

173
00:12:54,000 --> 00:13:01,000
Red Bull Market is overloaded and has versions that accepts in value and threat factor what is a threat

174
00:13:01,000 --> 00:13:01,000
factor.

175
00:13:02,000 --> 00:13:04,000
Let's open the source code of this type.

176
00:13:04,000 --> 00:13:11,000
Objects of a threat factory type are used to create new threats by giving implementation to the new

177
00:13:11,000 --> 00:13:12,000
threat massive.

178
00:13:12,000 --> 00:13:18,000
You can define the process and activities that are needed to be executed during the threat creation.

179
00:13:18,000 --> 00:13:24,000
Let me explain to you with the example I open threat factor factory demo file.

180
00:13:24,000 --> 00:13:29,000
I create a variable that would store WELI of number of threats in a threat posed.

181
00:13:30,000 --> 00:13:34,000
I create executive service and have fixed number of threats input.

182
00:13:35,000 --> 00:13:38,000
And when I create executive service, I call masses.

183
00:13:38,000 --> 00:13:41,000
It also takes threat factor as my argument.

184
00:13:41,000 --> 00:13:44,000
I pass object of the false threat factory type.

185
00:13:45,000 --> 00:13:46,000
What is this?

186
00:13:46,000 --> 00:13:49,000
This is my own implementation of threat factory interface.

187
00:13:50,000 --> 00:13:55,000
For the sake of the demo, I decided to keep all types in one demo file to not navigate between the

188
00:13:55,000 --> 00:13:58,000
multiple files of one example.

189
00:13:58,000 --> 00:14:01,000
And here I implemented Nusrat Masset.

190
00:14:01,000 --> 00:14:02,000
But why?

191
00:14:02,000 --> 00:14:08,000
We need to override process of threat creation and control it is the motivation to implement custom

192
00:14:08,000 --> 00:14:10,000
sweat factory is different.

193
00:14:10,000 --> 00:14:14,000
You may need to perform some additional actions before creating a threat.

194
00:14:14,000 --> 00:14:20,000
We need to create demon stress or for the debugging purposes, you need to name threats in a different

195
00:14:20,000 --> 00:14:21,000
way than mine.

196
00:14:21,000 --> 00:14:22,000
The different cases.

197
00:14:22,000 --> 00:14:25,000
Why you want to control process of threat creation.

198
00:14:26,000 --> 00:14:28,000
So you implemented a new threat.

199
00:14:28,000 --> 00:14:30,000
Massive in this case.

200
00:14:30,000 --> 00:14:33,000
I want to name threats for a different point.

201
00:14:33,000 --> 00:14:40,000
You can see that I created atomic integer counter and threats by adding value of my counter, incrementing

202
00:14:40,000 --> 00:14:41,000
it afterwards.

203
00:14:42,000 --> 00:14:42,000
That's it.

204
00:14:43,000 --> 00:14:51,000
Now, I said the same number of tasks I have for threats in goal and four tasks each task brings.

205
00:14:51,000 --> 00:14:55,000
Threatening to consult you can submit is a callable or runnable.

206
00:14:56,000 --> 00:14:58,000
Don't pay attention to a new threat.

207
00:14:58,000 --> 00:15:00,000
Must be acceptant Runnable.

208
00:15:00,000 --> 00:15:05,000
This is not directly connected in new executer you create a threat.

209
00:15:06,000 --> 00:15:12,000
Threats are created during the executive servicing utilization in this case and once threats are created,

210
00:15:13,000 --> 00:15:16,000
I submit tasks that will be implemented by these threats.

211
00:15:17,000 --> 00:15:20,000
Tasks may be easier of type runnable or callable.

212
00:15:20,000 --> 00:15:22,000
I keep command here.

213
00:15:22,000 --> 00:15:24,000
Example with Kobel task submission.

214
00:15:25,000 --> 00:15:29,000
Just in case you would like to uncommented and try once you would get the source code.

215
00:15:30,000 --> 00:15:35,000
Let's run this example and in console you might see the threats are different from default.

216
00:15:36,000 --> 00:15:41,000
This proves that Masset of the threat factor was used to create threats in the threat pool.

217
00:15:42,000 --> 00:15:42,000
Is that clear?

218
00:15:43,000 --> 00:15:44,000
Great.

219
00:15:44,000 --> 00:15:46,000
Let's move on now.

220
00:15:46,000 --> 00:15:49,000
Let's look at all the implementations of executive service interface.

221
00:15:50,000 --> 00:15:56,000
Probably remember that when we just first time created executive service, I used cached thread pool.

222
00:15:56,000 --> 00:16:00,000
Let's investigate this one in the source code of executive class.

223
00:16:00,000 --> 00:16:08,000
You can see that when I call New Castrato, I also creates red radical executer just with different

224
00:16:08,000 --> 00:16:08,000
arguments.

225
00:16:09,000 --> 00:16:16,000
So as you may already understand, these mass return us different versions of pre configure thread Thredbo

226
00:16:16,000 --> 00:16:19,000
executer to understand better.

227
00:16:19,000 --> 00:16:23,000
What is the difference between cash Stratego and fix reticle.

228
00:16:23,000 --> 00:16:29,000
Let's compare constructor arguments that are used during the initialization of threat to execute executer

229
00:16:29,000 --> 00:16:29,000
object.

230
00:16:30,000 --> 00:16:35,000
You can see that in cash streetball first two arguments are zero and max integer.

231
00:16:36,000 --> 00:16:40,000
These arguments are responsible to set Corpuz size and maximum pool size.

232
00:16:41,000 --> 00:16:43,000
What is Corpuz size does.

233
00:16:43,000 --> 00:16:47,000
This is a number of threats to keep in the pool, even if they're idle.

234
00:16:47,000 --> 00:16:53,000
How it is different from fixed threat pool infix threat pool equate specific number of threats.

235
00:16:53,000 --> 00:16:56,000
The number ipass as method argument is a.

236
00:16:56,000 --> 00:17:03,000
Plus size and the maximum size, the argument is a keep a lifetime when the number of threats is greater

237
00:17:03,000 --> 00:17:04,000
than the core.

238
00:17:04,000 --> 00:17:11,000
This is the maximum time that excess idle threats will wait for new tasks before terminated.

239
00:17:11,000 --> 00:17:14,000
We can see that they keep a lifetime in cash.

240
00:17:14,000 --> 00:17:18,000
Pool is 60 seconds and infix threat pools.

241
00:17:18,000 --> 00:17:20,000
This value is zero milliseconds.

242
00:17:20,000 --> 00:17:25,000
And the first argument is a cue that is used to store tasks before they're executed.

243
00:17:26,000 --> 00:17:31,000
We can see that in cash throughout threat pool, we use synchronous cue and then fixed threat pool.

244
00:17:31,000 --> 00:17:38,000
We use link, lock and key to what conclusion we may do based on these constructor arguments, these

245
00:17:38,000 --> 00:17:39,000
arguments.

246
00:17:39,000 --> 00:17:46,000
This means that the Casarett pool might grow without bounds to accommodate any number of submitted tasks.

247
00:17:46,000 --> 00:17:53,000
But when the threats are not needed anymore, they will be disposed of after 60 seconds of inactivity

248
00:17:53,000 --> 00:17:55,000
when it might be useful.

249
00:17:55,000 --> 00:18:01,000
For example, when we have a lot of shirtsleeve and tasks in application in a synchronous queue, each

250
00:18:01,000 --> 00:18:05,000
in search operation must wait for a corresponding remove operation.

251
00:18:06,000 --> 00:18:12,000
So we can say that pairs of insert and remove operations always occur simultaneously.

252
00:18:12,000 --> 00:18:15,000
That means that the queue never actually contains.

253
00:18:15,000 --> 00:18:18,000
Annison is as good for most cases.

254
00:18:18,000 --> 00:18:24,000
As I said before, it is good in case we have a lot of shirtsleeve and tasks, but this is not always

255
00:18:24,000 --> 00:18:24,000
the case.

256
00:18:25,000 --> 00:18:31,000
In other cases, using of threat cached pool may impact performance of our application in case with

257
00:18:31,000 --> 00:18:32,000
cash streetball.

258
00:18:32,000 --> 00:18:39,000
Each new task will create a new threat if all existing threats are busy and and reflect potential issues

259
00:18:39,000 --> 00:18:43,000
that might happen during the high load where you have to fix pool.

260
00:18:43,000 --> 00:18:50,000
In the best case, we may get a reservation situation at worst out of memory error.

261
00:18:50,000 --> 00:18:55,000
This is something that you need to consider when you decide to use pre configured threat pool executer

262
00:18:55,000 --> 00:18:58,000
created by new Casarett Pool Factory MassArt.

263
00:18:59,000 --> 00:19:04,000
Let's look at example now I open cash thread pool demo file here.

264
00:19:04,000 --> 00:19:08,000
We have similar example to one we have in the fixed thread pool demo file.

265
00:19:08,000 --> 00:19:15,000
The only difference is that I use different factor Massud from executor's class I call new cache streetball

266
00:19:15,000 --> 00:19:15,000
method.

267
00:19:16,000 --> 00:19:20,000
I submit for tasks and print, pool size and size.

268
00:19:20,000 --> 00:19:27,000
And as we expected, pool size will be equal to the number of submitted tasks in this case because each

269
00:19:27,000 --> 00:19:29,000
thread has leape inside.

270
00:19:30,000 --> 00:19:37,000
And by the moment new task is submitted, there are no available threats and new threat is created and

271
00:19:37,000 --> 00:19:43,000
queue size will be equal to zero because we are synchronous queue inside the threat to execute.

272
00:19:43,000 --> 00:19:44,000
Does it make sense?

273
00:19:45,000 --> 00:19:52,000
And also there is a factory method that takes threat factor as method argument so you can use it when

274
00:19:52,000 --> 00:19:52,000
needed.

275
00:19:53,000 --> 00:19:53,000
That's it.

276
00:19:53,000 --> 00:19:58,000
Regarding the cash threat pool, let's continue the next factory method.

277
00:19:58,000 --> 00:20:05,000
Probably not worse for a separate demo you can call new single thread executer this massive returns

278
00:20:05,000 --> 00:20:08,000
and executive service that manages one thread.

279
00:20:09,000 --> 00:20:15,000
If this single thread terminates due to a failure during the execution prior to shutdown, a new one

280
00:20:15,000 --> 00:20:19,000
will take its place if needed to execute subsequent tasks.

281
00:20:19,000 --> 00:20:26,000
Tasks are guaranteed to execute sequentially, and no more than one task will be active at any given

282
00:20:26,000 --> 00:20:26,000
time.

283
00:20:27,000 --> 00:20:34,000
Additionally, this Red Bull executer is decorated with an immutable wrapper so it can be reconfigured

284
00:20:34,000 --> 00:20:35,000
after creation.

285
00:20:36,000 --> 00:20:38,000
Let's return now skinless Red Bull.

286
00:20:38,000 --> 00:20:45,000
Executer we have to factor masses in executor's class that allows us to create executor's service of

287
00:20:45,000 --> 00:20:49,000
this type ZAYA News kidlets red pool within the parameters.

288
00:20:49,000 --> 00:20:55,000
It describes a number of course, threads and overloaded masses that takes that factory as an additional

289
00:20:55,000 --> 00:20:57,000
argument in the source code.

290
00:20:57,000 --> 00:21:00,000
We can use it on an instance of scandals.

291
00:21:00,000 --> 00:21:02,000
Reppel exactly the type.

292
00:21:02,000 --> 00:21:05,000
Let's open it and investigate this type.

293
00:21:05,000 --> 00:21:13,000
As we can see from the time declaration, it extends red executer and implements kidlet executive service

294
00:21:13,000 --> 00:21:17,000
interface, which in turn extends executive service interface.

295
00:21:18,000 --> 00:21:22,000
We need to understand what new behavior is introduced by scheduled executive service.

296
00:21:23,000 --> 00:21:30,000
Basically for new methods are introduced on Vermonter's cattle methods it takes is a random object.

297
00:21:31,000 --> 00:21:35,000
This method allows us to run a task once after a specified delay.

298
00:21:36,000 --> 00:21:43,000
Also cattle at fixed rate mass that allows us to run a task after a specified initial delay and then

299
00:21:43,000 --> 00:21:46,000
run it repeatedly with a certain period.

300
00:21:46,000 --> 00:21:51,000
The period argument is a time measured between the starting times of the tasks.

301
00:21:51,000 --> 00:21:53,000
So the execution rate is fixed.

302
00:21:54,000 --> 00:21:56,000
Schedule was fixed, the.

303
00:21:56,000 --> 00:22:02,000
A.M. is similar to scheduled at a fixed rate in that it would be the difference as a given task, but

304
00:22:02,000 --> 00:22:09,000
the specified delay is measured between the end of the previous task and start of the next task.

305
00:22:09,000 --> 00:22:14,000
Its execution rate may vary depending on the time it takes to run any given task.

306
00:22:15,000 --> 00:22:20,000
Let's open skidoos, read to them clause to review, quote, examples with this executer.

307
00:22:21,000 --> 00:22:26,000
The first example just shows us how to execute some task after initial delay.

308
00:22:27,000 --> 00:22:30,000
I create executer calls Macit.

309
00:22:30,000 --> 00:22:34,000
I just want to bring threatening to cancel after one second delay.

310
00:22:34,000 --> 00:22:36,000
This all tasks that I want to schedule.

311
00:22:37,000 --> 00:22:39,000
Let's run this program in console.

312
00:22:39,000 --> 00:22:42,000
We can see that threatening has been printed.

313
00:22:42,000 --> 00:22:46,000
This is how simple you must kill task for execution.

314
00:22:46,000 --> 00:22:54,000
Now I open scattered pull them two in this file we have them off schedule at fixed rate and schedule.

315
00:22:54,000 --> 00:22:59,000
With delay I create executer and then Wolk's cattle at fixed rate.

316
00:22:59,000 --> 00:23:06,000
Initial delay is five hundred milliseconds and after that start of each new task in each one second

317
00:23:07,000 --> 00:23:11,000
after seven seconds waiting, we shut down our executive service.

318
00:23:12,000 --> 00:23:18,000
I printer separator here and after that I create new executer and then walks schedule with a fixed delay.

319
00:23:19,000 --> 00:23:25,000
I am going to run the program and I'd like you pay attention to the fact that these two masses will

320
00:23:25,000 --> 00:23:32,000
work slightly differently because they track the same interval a little bit differently from start of

321
00:23:32,000 --> 00:23:40,000
one task to start of another task and from finish off one task to start off another task, I intentionally

322
00:23:40,000 --> 00:23:42,000
added sleep in each task.

323
00:23:42,000 --> 00:23:49,000
In this case, we may notice how in the first case, new task is executed each second, and in the second

324
00:23:49,000 --> 00:23:57,000
case, each task is executed approximately one and a half second because interval is measured between

325
00:23:57,000 --> 00:24:00,000
end of the one task and start of another task.

326
00:24:00,000 --> 00:24:02,000
And each task has sleep inside.

327
00:24:03,000 --> 00:24:07,000
I run the program and you can watch the result and feel the difference.

328
00:24:08,000 --> 00:24:09,000
Can you see the difference?

329
00:24:10,000 --> 00:24:15,000
Hope that with this example it is clear HouseCalls Reticule executive works.

330
00:24:15,000 --> 00:24:21,000
Also, we have similar factory method, but just for executer with one thread you can use three single

331
00:24:21,000 --> 00:24:24,000
threads candidate executive factory method to create similar.

332
00:24:24,000 --> 00:24:26,000
Executer was one thread.

333
00:24:26,000 --> 00:24:32,000
You can see that there is a wrapper here that exposes only the scheduled executive service methods of

334
00:24:32,000 --> 00:24:38,000
a scheduled executive service implementation and service over overloaded method that takes threat factor

335
00:24:38,000 --> 00:24:45,000
as method argument removed almost all factory methods to create different executive services.

336
00:24:45,000 --> 00:24:51,000
We still need to learn for doing framework to understand how, for example, works.

337
00:24:52,000 --> 00:24:56,000
That's why we'll review new works to improve Masset in the next lesson.

338
00:24:56,000 --> 00:24:57,000
That's it for today.

339
00:24:58,000 --> 00:25:01,000
Let's review what we have learned today in this lesson.

340
00:25:01,000 --> 00:25:05,000
In this lesson, we learn different implementations of executive services.

341
00:25:06,000 --> 00:25:11,000
We learn thread pool, executive class and how to create a fixed threat pool and cache threat pool.

342
00:25:12,000 --> 00:25:16,000
Now, you know the difference in these pro configurator threat pools.

343
00:25:16,000 --> 00:25:22,000
Also, you know the formula and the rules that will help you to calculate the ideal number of threats

344
00:25:22,000 --> 00:25:24,000
to create in the threat pool.

345
00:25:24,000 --> 00:25:28,000
Also, we learned how to work with threat factory after this lesson.

346
00:25:28,000 --> 00:25:32,000
You know how to work with a single threat pool and scandalous threat pool.

347
00:25:32,000 --> 00:25:35,000
Executer that's all what I have for you for this lesson.

348
00:25:36,000 --> 00:25:37,000
Thanks a lot for your attention.

349
00:25:38,000 --> 00:25:40,000
Have a great day and see you in the next lesson.