File size: 8,765 Bytes
1b558aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1
00:00:05,000 --> 00:00:06,000
Hello.

2
00:00:06,000 --> 00:00:10,000
And this week, we're going to review tasks for multithreaded topic.

3
00:00:10,000 --> 00:00:16,000
Now you have enough knowledge to deal with them and even more by this moment, we've learned so many

4
00:00:16,000 --> 00:00:19,000
things that you can solve the same tasks with multiple ways.

5
00:00:20,000 --> 00:00:26,000
For example, you can solve synchronization task with synchronized Massud, synchronized Bloks Locks

6
00:00:26,000 --> 00:00:27,000
or Synchronizer.

7
00:00:27,000 --> 00:00:29,000
And let's review tasks first.

8
00:00:29,000 --> 00:00:33,000
And after that I will tell you where you can find solution for these tasks in order.

9
00:00:33,000 --> 00:00:35,000
You could check a solution later.

10
00:00:36,000 --> 00:00:43,000
So in this file, you can find all home tasks that I recommend to implement to make sure you have enough

11
00:00:43,000 --> 00:00:44,000
skills in most certain programming.

12
00:00:45,000 --> 00:00:50,000
We are going to start from the super simple and gradually come to more complex tasks.

13
00:00:50,000 --> 00:00:56,000
You can find the reference to this file in attachments to the lesson that's reviewed these tasks together,

14
00:00:56,000 --> 00:00:58,000
and I will give my comments as we go.

15
00:00:59,000 --> 00:01:01,000
The first task is simple one.

16
00:01:01,000 --> 00:01:07,000
And just to practice your skills in creating stress in different ways and being able to interrupt threats,

17
00:01:07,000 --> 00:01:14,000
it is recommended to create and start a threat in four different ways by implementing runnable interface,

18
00:01:14,000 --> 00:01:20,000
by extending from STREAT class, bypassing the function to constructor of the class and bypassing the

19
00:01:20,000 --> 00:01:24,000
master reference during the threat objects instantiation.

20
00:01:24,000 --> 00:01:30,000
All of these ways were revealed in this course, so don't hesitate to navigate between the lessons to

21
00:01:30,000 --> 00:01:31,000
find the answer to this question.

22
00:01:32,000 --> 00:01:37,000
The next task is a little bit more complex than the first one, but still, I'm sure it will be easy

23
00:01:37,000 --> 00:01:39,000
for you to implement.

24
00:01:39,000 --> 00:01:45,000
You need to create some type that will spam messages with a specified interval of time.

25
00:01:45,000 --> 00:01:51,000
And also you need to implement logic of threat interruption after enter key press.

26
00:01:51,000 --> 00:01:53,000
I can give a hint you're here.

27
00:01:53,000 --> 00:02:00,000
You can try to implement this logic by creating a separate demon threat that would constantly listen

28
00:02:00,000 --> 00:02:01,000
for new line character.

29
00:02:01,000 --> 00:02:07,000
Zitter similar to press and enter during the program execution and once new line character is received,

30
00:02:07,000 --> 00:02:10,000
we interrupt this bomb threat.

31
00:02:10,000 --> 00:02:16,000
Besides the knowledge of mooches threat, this task also and needs knowledge of input output streams

32
00:02:16,000 --> 00:02:17,000
in Java.

33
00:02:17,000 --> 00:02:24,000
In case you have never worked with AI streams, please watch my Java course, namely section about inputs

34
00:02:24,000 --> 00:02:25,000
and outputs streams in Java.

35
00:02:26,000 --> 00:02:33,000
The shared task is already about synchronization similar to the ones that we have reviewed in lessons,

36
00:02:33,000 --> 00:02:39,000
but again seen task solution in the lesson and trying to implement it by itself.

37
00:02:39,000 --> 00:02:40,000
It is different things.

38
00:02:40,000 --> 00:02:46,000
So try to implement this task and understand better how SYNCHRONIZE Block works.

39
00:02:47,000 --> 00:02:54,000
Task number four is a little bit more complex and sure, you have to find a maximum number in multidimensional

40
00:02:54,000 --> 00:02:54,000
array.

41
00:02:55,000 --> 00:03:01,000
It is recommended to create Israelian solution and single resolution in order you could see the benefits

42
00:03:01,000 --> 00:03:03,000
of concurrent compute.

43
00:03:03,000 --> 00:03:08,000
And also I recommend to solve this task twice in order to practice different things.

44
00:03:09,000 --> 00:03:15,000
The first variant will be implementation was callable and future objects and the second variant will

45
00:03:15,000 --> 00:03:16,000
be implementation.

46
00:03:16,000 --> 00:03:18,000
With Countdown Lache Object.

47
00:03:18,000 --> 00:03:24,000
Implementing this task force two different ways will let you understand how these two solutions are

48
00:03:24,000 --> 00:03:24,000
different.

49
00:03:24,000 --> 00:03:27,000
And what would you prefer to use in your projects?

50
00:03:27,000 --> 00:03:29,000
And the last but not the least task.

51
00:03:29,000 --> 00:03:33,000
Number five, the standard task about writers and readers.

52
00:03:33,000 --> 00:03:39,000
Few students of mine has been asked to implement task and board readers and writers during the interviews.

53
00:03:39,000 --> 00:03:42,000
This proves that this kind of tasks are popular.

54
00:03:42,000 --> 00:03:48,000
During the interviews you have to implement reader and writer type and create objects of these types

55
00:03:48,000 --> 00:03:49,000
that would work together.

56
00:03:50,000 --> 00:03:53,000
Writer writes to the buffer readers read from above.

57
00:03:54,000 --> 00:03:55,000
Everything is simple.

58
00:03:55,000 --> 00:03:57,000
In the case there is nothing in Buffer.

59
00:03:57,000 --> 00:04:03,000
Something should be written there in case Buffer is full, massages should be consumed.

60
00:04:03,000 --> 00:04:08,000
There are some specific conditions that I would like you to implement in your solution.

61
00:04:08,000 --> 00:04:12,000
For example, limit your demo with three cycles of writing and reading.

62
00:04:13,000 --> 00:04:15,000
Limit your demo to three readers and one writer.

63
00:04:15,000 --> 00:04:20,000
Only total duration of the program execution should not be longer than two seconds.

64
00:04:21,000 --> 00:04:22,000
This check is also important.

65
00:04:22,000 --> 00:04:29,000
In order you do not build logical thread synchronization, only using stress loops similar to the previous

66
00:04:29,000 --> 00:04:29,000
task.

67
00:04:29,000 --> 00:04:32,000
I'd like to ask you to implement this task in two different ways.

68
00:04:33,000 --> 00:04:38,000
The first option is implementation with dummy object that will be used as monitor to synchronize all

69
00:04:38,000 --> 00:04:38,000
threads.

70
00:04:39,000 --> 00:04:45,000
Also, you can practice in using weight, modify and modify all methods and the second option is implementation.

71
00:04:45,000 --> 00:04:52,000
With the API, it would be just perfect for you to understand how to use logs in places where we use

72
00:04:52,000 --> 00:04:54,000
synchronize blocks and how flexible they are.

73
00:04:55,000 --> 00:04:58,000
The reference to the source code of the solution to these tasks.

74
00:04:58,000 --> 00:05:02,000
You can also find in attachments to the lesson in.

75
00:05:02,000 --> 00:05:08,000
If you already pulled my cloning project, you can find all solutions and different versions of solutions

76
00:05:08,000 --> 00:05:14,000
in the multiscreen package in Homburg package, all tasks have no in their name.

77
00:05:15,000 --> 00:05:20,000
So I'm sure it would be easy for you to navigate between them, but try to solve tasks and buy yourself

78
00:05:20,000 --> 00:05:21,000
first.

79
00:05:21,000 --> 00:05:27,000
And after that, look at the solution in case for some reasons it is hard for you to solve some task.

80
00:05:27,000 --> 00:05:30,000
Try to watch less than about a specific topic one more time.

81
00:05:31,000 --> 00:05:35,000
If this still doesn't help, try to look at a solution and rewrite it.

82
00:05:35,000 --> 00:05:42,000
As you understood, the things that I am trying to achieve is that you're trying to understand the solution,

83
00:05:42,000 --> 00:05:43,000
but not just do it.

84
00:05:44,000 --> 00:05:48,000
And remember, you are going to make a mistakes and that is fine.

85
00:05:48,000 --> 00:05:50,000
Not learning from that mistakes.

86
00:05:50,000 --> 00:05:52,000
It is the biggest mistake.

87
00:05:53,000 --> 00:05:54,000
These are all tasks.

88
00:05:55,000 --> 00:05:57,000
You are more than welcome to ask questions.

89
00:05:57,000 --> 00:05:59,000
And as a beginner, in case of any.

90
00:05:59,000 --> 00:06:00,000
That's it.

91
00:06:00,000 --> 00:06:03,000
Thank you for your attention and see you in the next Larsons.