diff --git a/.gitattributes b/.gitattributes
index 2cc926a187f5adadbb3e3cf74fb18fe21c1fe68d..bd92eef841867f97aafdd4bb69777e05ca346124 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -65,3 +65,11 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
07[[:space:]]-[[:space:]]Control[[:space:]]Statements/007[[:space:]]Homework[[:space:]]review[[:space:]]'switch'[[:space:]]statement.mp4 filter=lfs diff=lfs merge=lfs -text
08[[:space:]]-[[:space:]]Miscellaneous/001[[:space:]]Random[[:space:]]numbers[[:space:]]generation.mp4 filter=lfs diff=lfs merge=lfs -text
07[[:space:]]-[[:space:]]Control[[:space:]]Statements/005[[:space:]]'switch'[[:space:]]construction.mp4 filter=lfs diff=lfs merge=lfs -text
+09[[:space:]]-[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops)[[:space:]]in[[:space:]]Java/001[[:space:]]'while'[[:space:]]loop.mp4 filter=lfs diff=lfs merge=lfs -text
+09[[:space:]]-[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops)[[:space:]]in[[:space:]]Java/002[[:space:]]'do-while'[[:space:]]loop.mp4 filter=lfs diff=lfs merge=lfs -text
+09[[:space:]]-[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops)[[:space:]]in[[:space:]]Java/004[[:space:]]'for[[:space:]]each'[[:space:]]loop.mp4 filter=lfs diff=lfs merge=lfs -text
+09[[:space:]]-[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops)[[:space:]]in[[:space:]]Java/003[[:space:]]'for'[[:space:]]with[[:space:]]condition[[:space:]]loop.mp4 filter=lfs diff=lfs merge=lfs -text
+09[[:space:]]-[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops)[[:space:]]in[[:space:]]Java/005[[:space:]]Nested[[:space:]]loops.mp4 filter=lfs diff=lfs merge=lfs -text
+09[[:space:]]-[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops)[[:space:]]in[[:space:]]Java/006[[:space:]]Jump[[:space:]]Statements[[:space:]]-[[:space:]]Break[[:space:]]and[[:space:]]Continue.mp4 filter=lfs diff=lfs merge=lfs -text
+09[[:space:]]-[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops)[[:space:]]in[[:space:]]Java/007[[:space:]]Labels[[:space:]]in[[:space:]]Java.mp4 filter=lfs diff=lfs merge=lfs -text
+09[[:space:]]-[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops)[[:space:]]in[[:space:]]Java/011[[:space:]]Homework[[:space:]]review[[:space:]]Iteration[[:space:]]Statements[[:space:]](Loops).mp4 filter=lfs diff=lfs merge=lfs -text
diff --git a/09 - Iteration Statements (Loops) in Java/001 'while' loop.mp4 b/09 - Iteration Statements (Loops) in Java/001 'while' loop.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..885640d10c222d4645e6bf20d9fdc9392ee7a92e
--- /dev/null
+++ b/09 - Iteration Statements (Loops) in Java/001 'while' loop.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:c629d1d6f638fb968214957658e97c6eb23095272a0bbe7087e6c1348b9c13f0
+size 27823271
diff --git a/09 - Iteration Statements (Loops) in Java/002 'do-while' loop.mp4 b/09 - Iteration Statements (Loops) in Java/002 'do-while' loop.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..0cf7bcd1870166ecb58902084b322a5ff62e6abe
--- /dev/null
+++ b/09 - Iteration Statements (Loops) in Java/002 'do-while' loop.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:5eb2e2c5e7fa0f6dd1adca8edbfab3a5e65e319870309f617ff33511a4dca3f3
+size 35783857
diff --git a/09 - Iteration Statements (Loops) in Java/003 'for' with condition loop.mp4 b/09 - Iteration Statements (Loops) in Java/003 'for' with condition loop.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..9a0317d4ed28c02b987ec28dad4bd0065f749462
--- /dev/null
+++ b/09 - Iteration Statements (Loops) in Java/003 'for' with condition loop.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:ec119ea6d92fcd2a3e8d78f2f667e382468584679b989705b9634e0732800192
+size 63924486
diff --git a/09 - Iteration Statements (Loops) in Java/004 'for each' loop.mp4 b/09 - Iteration Statements (Loops) in Java/004 'for each' loop.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..003e3bc85ec30b3f3e9e959b83c52b23f7a4fb6b
--- /dev/null
+++ b/09 - Iteration Statements (Loops) in Java/004 'for each' loop.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:71190e257dd46f2405ec5bb73456ccb7cb82f788203ef363051da9451bb18b32
+size 37813640
diff --git a/09 - Iteration Statements (Loops) in Java/005 Nested loops.mp4 b/09 - Iteration Statements (Loops) in Java/005 Nested loops.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..d0b210a0aeab3511bb60888fda5b5f6762470cc2
--- /dev/null
+++ b/09 - Iteration Statements (Loops) in Java/005 Nested loops.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:b67654f3d53938bf16e584d8ceb6b56cb940f55c5d8368de61776bf849b63161
+size 20391609
diff --git a/09 - Iteration Statements (Loops) in Java/006 Jump Statements - Break and Continue.mp4 b/09 - Iteration Statements (Loops) in Java/006 Jump Statements - Break and Continue.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..9d90163849d053095f17de9e1b1c1060df9eb90f
--- /dev/null
+++ b/09 - Iteration Statements (Loops) in Java/006 Jump Statements - Break and Continue.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:0c422194b3c80416d91dd612aa7b34bb0fbd3688604d92bed32e47a808e4f942
+size 50604865
diff --git a/09 - Iteration Statements (Loops) in Java/007 Labels in Java.mp4 b/09 - Iteration Statements (Loops) in Java/007 Labels in Java.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..581a1e287c928306b8d4efe0ac3b0dc759cc5a29
--- /dev/null
+++ b/09 - Iteration Statements (Loops) in Java/007 Labels in Java.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:df3f86d63fc059acc141b4411ce931f9c3c444246d42669aa3b5e7d7dd0821c3
+size 61053752
diff --git a/09 - Iteration Statements (Loops) in Java/011 Homework review Iteration Statements (Loops).mp4 b/09 - Iteration Statements (Loops) in Java/011 Homework review Iteration Statements (Loops).mp4
new file mode 100644
index 0000000000000000000000000000000000000000..ebddf6b071d14d1a7d579eb526d400eef169adf6
--- /dev/null
+++ b/09 - Iteration Statements (Loops) in Java/011 Homework review Iteration Statements (Loops).mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:2522b8e6587dd3c05d2ed70e5944ba7ab190e5b0291ac55d1e7e5e22d7e2d34e
+size 28394427
diff --git a/22 - Functional Programming in Java (including lambda functions & method references)/004 Source-code-All-examples-from-the-lecture-CONSUMERS.url b/22 - Functional Programming in Java (including lambda functions & method references)/004 Source-code-All-examples-from-the-lecture-CONSUMERS.url
new file mode 100644
index 0000000000000000000000000000000000000000..1a445f177519d6821b5ffda72b5238d932a29dd0
--- /dev/null
+++ b/22 - Functional Programming in Java (including lambda functions & method references)/004 Source-code-All-examples-from-the-lecture-CONSUMERS.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/functions/consumers
\ No newline at end of file
diff --git a/22 - Functional Programming in Java (including lambda functions & method references)/004 Source-code-All-examples-from-the-lecture-PREDICATES.url b/22 - Functional Programming in Java (including lambda functions & method references)/004 Source-code-All-examples-from-the-lecture-PREDICATES.url
new file mode 100644
index 0000000000000000000000000000000000000000..b1bd2775cd32117451d25c1e917a5f2b78751a28
--- /dev/null
+++ b/22 - Functional Programming in Java (including lambda functions & method references)/004 Source-code-All-examples-from-the-lecture-PREDICATES.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/functions/predicates
\ No newline at end of file
diff --git a/22 - Functional Programming in Java (including lambda functions & method references)/external-links.txt b/22 - Functional Programming in Java (including lambda functions & method references)/external-links.txt
new file mode 100644
index 0000000000000000000000000000000000000000..321045a1acfd01d0e2e25caa14230b3c35e7f609
--- /dev/null
+++ b/22 - Functional Programming in Java (including lambda functions & method references)/external-links.txt
@@ -0,0 +1,21 @@
+
+001 Documentation-of-java.util.function-package
+https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/function/package-summary.html
+
+002 Source-code-All-examples-from-the-lecture
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/functions/lambdaandmethodreference
+
+003 Source-code-All-examples-from-the-lecture
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/functions/functionandbifunction
+
+004 Source-code-All-examples-from-the-lecture-CONSUMERS
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/functions/consumers
+
+004 Source-code-All-examples-from-the-lecture-PREDICATES
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/functions/predicates
+
+004 Homework
+https://docs.google.com/document/d/1hMA300MS2UJhRDfh5VUviGrGiQzfsV5rReH5KTwDdvc/edit?usp=sharing
+
+004 Solution-for-Homework
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/functions/hw
diff --git a/23 - Stream API/001 Documentation-for-java.util.stream-package.url b/23 - Stream API/001 Documentation-for-java.util.stream-package.url
new file mode 100644
index 0000000000000000000000000000000000000000..4c89d7e0846e046d01b0bdcdf18c59ee872dd391
--- /dev/null
+++ b/23 - Stream API/001 Documentation-for-java.util.stream-package.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/stream/package-summary.html
\ No newline at end of file
diff --git a/23 - Stream API/001 Homework-Solution-Books-Management.url b/23 - Stream API/001 Homework-Solution-Books-Management.url
new file mode 100644
index 0000000000000000000000000000000000000000..48e38842a6e6fd09064a390292b73591f42a9e7f
--- /dev/null
+++ b/23 - Stream API/001 Homework-Solution-Books-Management.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/oop/hw/books
\ No newline at end of file
diff --git a/23 - Stream API/001 Homework-Solution-Filter-words-by-length.url b/23 - Stream API/001 Homework-Solution-Filter-words-by-length.url
new file mode 100644
index 0000000000000000000000000000000000000000..24e715b6bcd8ca33f2e6fcecc39bd8f09be402b1
--- /dev/null
+++ b/23 - Stream API/001 Homework-Solution-Filter-words-by-length.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/methods/hw/FilterStringArray.java
\ No newline at end of file
diff --git a/23 - Stream API/001 Homework-Solution-Present-Sweets.url b/23 - Stream API/001 Homework-Solution-Present-Sweets.url
new file mode 100644
index 0000000000000000000000000000000000000000..cd235cf94c7c44290c547bcca6495420831a583f
--- /dev/null
+++ b/23 - Stream API/001 Homework-Solution-Present-Sweets.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/oop/hw/present
\ No newline at end of file
diff --git a/23 - Stream API/001 Homework.url b/23 - Stream API/001 Homework.url
new file mode 100644
index 0000000000000000000000000000000000000000..fd9a13aaf6359be8d683591d980d8149c7a4eb65
--- /dev/null
+++ b/23 - Stream API/001 Homework.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://docs.google.com/document/d/1TLRPMHsciAdeHn8XFWXQYrO3dVGv6b_THev6nKE2ewY/edit?usp=sharing
\ No newline at end of file
diff --git a/23 - Stream API/001 Source-code-All-examples-from-the-lecture.url b/23 - Stream API/001 Source-code-All-examples-from-the-lecture.url
new file mode 100644
index 0000000000000000000000000000000000000000..259d410afd54efb485e41053e898850ab02ee1ad
--- /dev/null
+++ b/23 - Stream API/001 Source-code-All-examples-from-the-lecture.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/functions/streams
\ No newline at end of file
diff --git a/23 - Stream API/001 Stream API with Practical Exercises_en.srt b/23 - Stream API/001 Stream API with Practical Exercises_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..ccdb842a536687f82da31024466f7c5226d13f64
--- /dev/null
+++ b/23 - Stream API/001 Stream API with Practical Exercises_en.srt
@@ -0,0 +1,1312 @@
+1
+00:00:05,000 --> 00:00:10,000
+I know there are students in this class and we're going to discuss topics that will help to make your
+
+2
+00:00:10,000 --> 00:00:13,000
+code clean and concise while working with collections in the race.
+
+3
+00:00:14,000 --> 00:00:19,000
+They will talk about Stream API at the beginning of the lesson, will give an answer what stream API
+
+4
+00:00:19,000 --> 00:00:20,000
+is.
+
+5
+00:00:20,000 --> 00:00:26,000
+I will explain to you why we need to use three API with race and collection sometimes after this class
+
+6
+00:00:26,000 --> 00:00:31,000
+and you will understand what the conveyor belt is and what terminal and non terminal operations are.
+
+7
+00:00:32,000 --> 00:00:37,000
+You are going to learn how to create stream and how to process elements with the help of Stream API.
+
+8
+00:00:37,000 --> 00:00:40,000
+I'm going to show you really a lot of examples today.
+
+9
+00:00:40,000 --> 00:00:46,000
+I will teach you how to create a stream from array and how to convert at to map with the help of Stream
+
+10
+00:00:46,000 --> 00:00:46,000
+API.
+
+11
+00:00:46,000 --> 00:00:52,000
+In this lesson, we are going to have a lot of practice because one of the ways to understand this topic
+
+12
+00:00:52,000 --> 00:00:56,000
+better is to understand how you can apply this knowledge on practice.
+
+13
+00:00:56,000 --> 00:01:01,000
+Let's start and to start with, let's create a definition of stream API.
+
+14
+00:01:02,000 --> 00:01:07,000
+If we would open official documentation from Oracle for Jayaweera to Stream Package will see that this
+
+15
+00:01:07,000 --> 00:01:14,000
+package contains classes to support functional style operations on streams of elements such as mass
+
+16
+00:01:14,000 --> 00:01:16,000
+produced transformations, onco actions.
+
+17
+00:01:17,000 --> 00:01:22,000
+I believe for people who didn't work with streams, this definition doesn't bring a lot of clarity.
+
+18
+00:01:22,000 --> 00:01:24,000
+So let me explain you the same.
+
+19
+00:01:24,000 --> 00:01:31,000
+In more simple words, stream application programming interface is a set of interfaces that allow to
+
+20
+00:01:31,000 --> 00:01:37,000
+process elements and to perform operations with them in containers and arrays with the help of functional
+
+21
+00:01:37,000 --> 00:01:38,000
+interfaces.
+
+22
+00:01:39,000 --> 00:01:45,000
+So to perform operation on the group of elements, you can create lambda functions or use Macit references
+
+23
+00:01:45,000 --> 00:01:49,000
+that in turn significantly simplifies your code.
+
+24
+00:01:49,000 --> 00:01:50,000
+Does it make sense?
+
+25
+00:01:51,000 --> 00:01:56,000
+Now let me perform an overview of one important interface from Jowett Ustream package.
+
+26
+00:01:56,000 --> 00:02:00,000
+This will help you to understand our practice examples.
+
+27
+00:02:00,000 --> 00:02:05,000
+I would say that one of the most important interfaces is stream interface.
+
+28
+00:02:05,000 --> 00:02:11,000
+What it is for string interface represents a sequence of elements supporting sequential and parallel
+
+29
+00:02:11,000 --> 00:02:13,000
+aggregate operations.
+
+30
+00:02:13,000 --> 00:02:15,000
+This is hard to understand.
+
+31
+00:02:15,000 --> 00:02:17,000
+Believe me, I know what you feel.
+
+32
+00:02:17,000 --> 00:02:24,000
+Usually I ask my students to imagine conveyor belt and on this conveyor you have elements from your
+
+33
+00:02:24,000 --> 00:02:31,000
+collection and as a conveyor belt rolling, you take each element from it and perform any modifications
+
+34
+00:02:31,000 --> 00:02:32,000
+with it.
+
+35
+00:02:33,000 --> 00:02:38,000
+Before we dive deeper to code examples, I want you to understand, at least on a high level, the next
+
+36
+00:02:38,000 --> 00:02:39,000
+example.
+
+37
+00:02:39,000 --> 00:02:46,000
+Imagine that you have a list of products and you have a task to keep on that products that has more
+
+38
+00:02:46,000 --> 00:02:53,000
+than one thousand items in the warehouse and decrease price for these products on 10 percent.
+
+39
+00:02:53,000 --> 00:02:59,000
+This business logic should change the price for products, and this in turn should motivate customers
+
+40
+00:02:59,000 --> 00:03:03,000
+of the online store to buy these products while price is reduced.
+
+41
+00:03:04,000 --> 00:03:05,000
+How would you do that?
+
+42
+00:03:05,000 --> 00:03:08,000
+You would create the container of products.
+
+43
+00:03:08,000 --> 00:03:14,000
+Let's imagine that this is a box that is full of products and put all products on conveyor belt.
+
+44
+00:03:14,000 --> 00:03:19,000
+After that, you will check what products has more than one thousand items in warehouse.
+
+45
+00:03:20,000 --> 00:03:24,000
+You will remove from Canberra products that you are not interested in.
+
+46
+00:03:24,000 --> 00:03:29,000
+That means you have to apply a function that knows how to filter elements.
+
+47
+00:03:29,000 --> 00:03:32,000
+After that, you will modify price for each product.
+
+48
+00:03:33,000 --> 00:03:40,000
+That means you have to apply functions that modify state of the product and only after that the end
+
+49
+00:03:40,000 --> 00:03:44,000
+of the conveyor belt, you would gather all elements together back to the box.
+
+50
+00:03:45,000 --> 00:03:52,000
+Is it clear now you can understand that the functions that was applied for each element on the conveyor
+
+51
+00:03:52,000 --> 00:03:55,000
+belt, they are called non terminal also.
+
+52
+00:03:55,000 --> 00:04:02,000
+They might be called intermediate functions or it would be opportunism, conveyor operations and the
+
+53
+00:04:02,000 --> 00:04:06,000
+mass that terminate conveyor are called terminal operations.
+
+54
+00:04:07,000 --> 00:04:15,000
+We also can say that each non terminal operation at Listener to the Stream listener modifies the element
+
+55
+00:04:15,000 --> 00:04:17,000
+and pass it to another listener.
+
+56
+00:04:17,000 --> 00:04:22,000
+This is called stream processing terminal and non terminal operations.
+
+57
+00:04:22,000 --> 00:04:24,000
+Create Stream Pipeline.
+
+58
+00:04:24,000 --> 00:04:31,000
+Stream Pipeline consists of the source that is our collection of elements or array followed by intermediate
+
+59
+00:04:31,000 --> 00:04:34,000
+operations and ended with terminal operation.
+
+60
+00:04:35,000 --> 00:04:37,000
+Let's consider another case.
+
+61
+00:04:37,000 --> 00:04:39,000
+You may have multiple lists of products.
+
+62
+00:04:39,000 --> 00:04:40,000
+How it can be.
+
+63
+00:04:41,000 --> 00:04:48,000
+You have different warehouses and each warehouse contains information about the products there.
+
+64
+00:04:48,000 --> 00:04:52,000
+So you have multiple lists of products from each warehouse.
+
+65
+00:04:53,000 --> 00:04:59,000
+This may happen when Demand-Driven design of your application declares that you have type warehouse
+
+66
+00:04:59,000 --> 00:05:01,000
+that in turn can return list of products.
+
+67
+00:05:02,000 --> 00:05:08,000
+And imagine that you have a list, our houses in our example, you have a lot of their houses with products
+
+68
+00:05:09,000 --> 00:05:15,000
+we can create, can aware of their houses, but we can also have the functions that would tell how to
+
+69
+00:05:15,000 --> 00:05:20,000
+extract products from these warehouses to have conveyor of products.
+
+70
+00:05:20,000 --> 00:05:25,000
+And after that, we are going to have similar to previous example, logic will filter elements and will
+
+71
+00:05:25,000 --> 00:05:28,000
+perform price modification, I believe.
+
+72
+00:05:28,000 --> 00:05:31,000
+Now you understand what we are going to learn today.
+
+73
+00:05:32,000 --> 00:05:37,000
+We're going to learn terminal and not terminal functions to perform operations with elements in streams.
+
+74
+00:05:38,000 --> 00:05:42,000
+Now, let's look at the good examples that I prepared for this lesson.
+
+75
+00:05:42,000 --> 00:05:49,000
+To understand how streams work will start from reproducing the case that you saw on slides.
+
+76
+00:05:49,000 --> 00:05:56,000
+All classes are stored in one file to keep all examples related to this lesson grouped and to not switch
+
+77
+00:05:56,000 --> 00:05:58,000
+between the different types during the lesson.
+
+78
+00:05:58,000 --> 00:06:03,000
+Here we have a class in its price name and the amount of items in their house.
+
+79
+00:06:04,000 --> 00:06:10,000
+Also, you can see a special constructor getters and setters to string Masset for the bag and purposes.
+
+80
+00:06:11,000 --> 00:06:15,000
+And here you can see a warehouse type for the sake of our next examples.
+
+81
+00:06:15,000 --> 00:06:18,000
+This class has only one field list of products.
+
+82
+00:06:19,000 --> 00:06:24,000
+Also, there are two masses, getter and setter, to retrieve and to set products accordingly.
+
+83
+00:06:25,000 --> 00:06:27,000
+Now imagine that I have a list of products.
+
+84
+00:06:27,000 --> 00:06:34,000
+You can see that I created multiple different products here and put all of them into the list to create
+
+85
+00:06:34,000 --> 00:06:34,000
+stream.
+
+86
+00:06:34,000 --> 00:06:40,000
+From this list, I have to just go through Method Stream is the default method in collection interface.
+
+87
+00:06:41,000 --> 00:06:44,000
+So all collections have be method.
+
+88
+00:06:44,000 --> 00:06:49,000
+After we create a stream we can call intermediate operations and at least inners.
+
+89
+00:06:49,000 --> 00:06:54,000
+For example, let's reproduce a situation from the slides that we saw at the beginning of our lesson
+
+90
+00:06:55,000 --> 00:06:56,000
+I call filter method.
+
+91
+00:06:57,000 --> 00:06:58,000
+Let me open the source code of Feltham.
+
+92
+00:06:58,000 --> 00:07:06,000
+As you can see, that filter method takes predicate all intermediate functions, return the stream objects
+
+93
+00:07:06,000 --> 00:07:10,000
+that allows us to create a chain of MassArt in locations.
+
+94
+00:07:10,000 --> 00:07:16,000
+Filter message returns a stream consisting of the elements of the stream that match the given predicate.
+
+95
+00:07:17,000 --> 00:07:23,000
+That means in case predicates returns true for some element, we should keep this element in the stream.
+
+96
+00:07:24,000 --> 00:07:26,000
+Let's get back to the demo file.
+
+97
+00:07:26,000 --> 00:07:28,000
+We use simple predicate here.
+
+98
+00:07:29,000 --> 00:07:35,000
+We want to keep on our conveyor belt only products that have more than 1000 items in the warehouse.
+
+99
+00:07:36,000 --> 00:07:39,000
+After that, I want to apply function to each element.
+
+100
+00:07:40,000 --> 00:07:42,000
+I use math method for this.
+
+101
+00:07:42,000 --> 00:07:45,000
+Let me open the source code of math, Macit.
+
+102
+00:07:46,000 --> 00:07:52,000
+This message returns a stream consisting of the results of a the given function to the aliments in the
+
+103
+00:07:52,000 --> 00:07:52,000
+stream.
+
+104
+00:07:53,000 --> 00:07:59,000
+In our particular case, we modify product and we return the same product to the stream we set.
+
+105
+00:07:59,000 --> 00:08:02,000
+The new price set is ten percent less than the original.
+
+106
+00:08:02,000 --> 00:08:07,000
+One important thing to know here is that intermediate operations are lazy.
+
+107
+00:08:08,000 --> 00:08:14,000
+This means that they will be invoked only if it is necessary for the terminal operation execution.
+
+108
+00:08:14,000 --> 00:08:21,000
+Let's give you the understanding that this lambda functions will be executed only in case a terminal
+
+109
+00:08:21,000 --> 00:08:23,000
+operation and the end of the chain.
+
+110
+00:08:23,000 --> 00:08:29,000
+And now when I did everything I wanted, I want to create a collection of items that are currently on
+
+111
+00:08:29,000 --> 00:08:32,000
+the conveyor belt I call terminal function collect.
+
+112
+00:08:33,000 --> 00:08:36,000
+Let's review the source code of collect Macit here.
+
+113
+00:08:36,000 --> 00:08:39,000
+We can see that this massive tax collector as an argument.
+
+114
+00:08:40,000 --> 00:08:41,000
+But what is a collector?
+
+115
+00:08:42,000 --> 00:08:45,000
+We have only one way to learn this from the source code.
+
+116
+00:08:45,000 --> 00:08:52,000
+We can understand that collector is a specific type that accumulates input elements into mutable result
+
+117
+00:08:52,000 --> 00:08:53,000
+content.
+
+118
+00:08:54,000 --> 00:08:56,000
+But where to get the implementation of collector?
+
+119
+00:08:57,000 --> 00:09:01,000
+Usually engineers use collectors glass to get any collector that is needed.
+
+120
+00:09:02,000 --> 00:09:08,000
+Let me show you the source code of collectors glass this glass also from Jemmett Ustream package.
+
+121
+00:09:08,000 --> 00:09:13,000
+And in the Masset outline you can see that we can get different collectors.
+
+122
+00:09:13,000 --> 00:09:20,000
+The most popular, in my opinion, are the ones that are returned by the next masses to least to set
+
+123
+00:09:20,000 --> 00:09:21,000
+the map.
+
+124
+00:09:21,000 --> 00:09:26,000
+Also, you can get collectors that will collect all your elements to modify modifiable least.
+
+125
+00:09:26,000 --> 00:09:30,000
+For example, most of the masses are describing here.
+
+126
+00:09:30,000 --> 00:09:34,000
+That's why I don't see the sense into naming all of this matter.
+
+127
+00:09:35,000 --> 00:09:40,000
+Just open the source code of this class to investigate what other collectors you can use.
+
+128
+00:09:40,000 --> 00:09:47,000
+By the way, at the end of the lesson, I will leave a cheat sheet for you where I will gather all the
+
+129
+00:09:47,000 --> 00:09:50,000
+most popular masses, including the terminal functions.
+
+130
+00:09:51,000 --> 00:09:53,000
+Let's get back to our demo file.
+
+131
+00:09:53,000 --> 00:09:58,000
+In this case, I want to group all elements from my stream into the container.
+
+132
+00:09:58,000 --> 00:10:01,000
+I call collect method and pass collect the.
+
+133
+00:10:01,000 --> 00:10:10,000
+Is it a might the least Masset implication, is this example clear so you can see massive change here
+
+134
+00:10:10,000 --> 00:10:14,000
+with multiple intermediate functions and then I have one terminal operation.
+
+135
+00:10:15,000 --> 00:10:17,000
+Where did they get these intermediate masses?
+
+136
+00:10:18,000 --> 00:10:20,000
+You can open string type to investigate.
+
+137
+00:10:20,000 --> 00:10:24,000
+The rest of the masses here will review these in a minute.
+
+138
+00:10:24,000 --> 00:10:26,000
+Let me finish the example we already started.
+
+139
+00:10:27,000 --> 00:10:29,000
+Let me get back to the demo file.
+
+140
+00:10:30,000 --> 00:10:35,000
+And after I created the list, I want to print all elements to console from the new line.
+
+141
+00:10:35,000 --> 00:10:40,000
+But instead of creating foreach loop, I will use the feature of Stream API.
+
+142
+00:10:40,000 --> 00:10:43,000
+I create a stream using the variable of modified products.
+
+143
+00:10:44,000 --> 00:10:51,000
+After that, I call for each method that takes consumer as an argument and I pass mast reference here
+
+144
+00:10:51,000 --> 00:10:54,000
+out property of a system class.
+
+145
+00:10:54,000 --> 00:10:59,000
+His method printer lan that we use very often during the bargain of our programs.
+
+146
+00:10:59,000 --> 00:11:05,000
+So I just use reference to this massive let me run the program to prove you that it works.
+
+147
+00:11:05,000 --> 00:11:07,000
+And here we go.
+
+148
+00:11:07,000 --> 00:11:11,000
+You can see that I have only three products with modified price.
+
+149
+00:11:11,000 --> 00:11:12,000
+Awesome.
+
+150
+00:11:12,000 --> 00:11:14,000
+Everything works as expected.
+
+151
+00:11:15,000 --> 00:11:19,000
+Now let me reproduce the second example from our presentation.
+
+152
+00:11:19,000 --> 00:11:22,000
+Imagine that we have multiple warehouses.
+
+153
+00:11:22,000 --> 00:11:25,000
+I create a few warehouses, objects here.
+
+154
+00:11:25,000 --> 00:11:27,000
+Each warehouse has lists of products.
+
+155
+00:11:28,000 --> 00:11:32,000
+That's why I add a different list of objects to the warehouses here.
+
+156
+00:11:33,000 --> 00:11:39,000
+And imagine we have to iterate over all products to decrease price only for products that have more
+
+157
+00:11:39,000 --> 00:11:41,000
+than 1000 items.
+
+158
+00:11:41,000 --> 00:11:46,000
+First of all, I group all my warehouse objects into one list.
+
+159
+00:11:46,000 --> 00:11:49,000
+Now I create a stream out of this list.
+
+160
+00:11:49,000 --> 00:11:52,000
+After that I call flat my math.
+
+161
+00:11:53,000 --> 00:11:54,000
+What is it for?
+
+162
+00:11:54,000 --> 00:12:02,000
+This method exists to extract elements from NASA once this method will return stream consistent of the
+
+163
+00:12:02,000 --> 00:12:09,000
+result of replacing each element of the stream with the contents of a mapped stream produced by applying
+
+164
+00:12:09,000 --> 00:12:13,000
+the provided map and function to each element.
+
+165
+00:12:13,000 --> 00:12:22,000
+Is it clear will path function to this method that will produce stream of elements from each element?
+
+166
+00:12:22,000 --> 00:12:29,000
+In our particular case, we have to get products from each warehouse object and create a stream on list
+
+167
+00:12:29,000 --> 00:12:30,000
+of products.
+
+168
+00:12:30,000 --> 00:12:38,000
+Before we call this flat map method, we have conveyor belt of warehouse elements and after we called
+
+169
+00:12:38,000 --> 00:12:41,000
+flat map, we have stream of product elements.
+
+170
+00:12:41,000 --> 00:12:46,000
+Can you understand now how we can transform data in our stream?
+
+171
+00:12:46,000 --> 00:12:51,000
+After that, we are filtering and applying function to all elements.
+
+172
+00:12:51,000 --> 00:12:53,000
+Now let me show you one more thing.
+
+173
+00:12:54,000 --> 00:13:00,000
+Imagine that according to some massive contracts requirements, you have to reach an array we can call
+
+174
+00:13:00,000 --> 00:13:02,000
+to array Massud instead of collect.
+
+175
+00:13:03,000 --> 00:13:07,000
+But in case we would just call Thouret Array method, we would get array of objects.
+
+176
+00:13:08,000 --> 00:13:14,000
+What to do in this case, I have to pass the Massud that will create array of the specific types that
+
+177
+00:13:14,000 --> 00:13:15,000
+I need.
+
+178
+00:13:15,000 --> 00:13:19,000
+What method can create an array of product constructor?
+
+179
+00:13:20,000 --> 00:13:28,000
+That's why I specify type here array of product and positive reference to a constructor according to
+
+180
+00:13:28,000 --> 00:13:29,000
+syntax requirements.
+
+181
+00:13:29,000 --> 00:13:31,000
+I have to write the new keyword here.
+
+182
+00:13:32,000 --> 00:13:34,000
+Can you understand now what this meant?
+
+183
+00:13:35,000 --> 00:13:38,000
+Now Java can create object of product array.
+
+184
+00:13:39,000 --> 00:13:43,000
+After that I want to print all elements to console from new line.
+
+185
+00:13:44,000 --> 00:13:48,000
+But we have an array this time can create stream from array.
+
+186
+00:13:48,000 --> 00:13:49,000
+Yes I can.
+
+187
+00:13:50,000 --> 00:13:54,000
+I have to call stream Massud from arrays class and parse array of products there.
+
+188
+00:13:55,000 --> 00:13:59,000
+That's how easily you can create three from any array.
+
+189
+00:13:59,000 --> 00:14:06,000
+Also during the discussion of functional interfaces, I promise to show you one method and how it might
+
+190
+00:14:06,000 --> 00:14:07,000
+be helpful.
+
+191
+00:14:07,000 --> 00:14:12,000
+While working with Stream API, I'm talking about identity Masset from function type.
+
+192
+00:14:13,000 --> 00:14:19,000
+Imagine that you want to convert list of products to the map type where you're going to have product
+
+193
+00:14:19,000 --> 00:14:23,000
+name as a key and product type as a value that is mapped to this key.
+
+194
+00:14:24,000 --> 00:14:25,000
+How to do that.
+
+195
+00:14:25,000 --> 00:14:30,000
+You'll remember at the beginning of the lesson I created products placed in this example.
+
+196
+00:14:30,000 --> 00:14:35,000
+I use the same list of products, I create stream code, collect method.
+
+197
+00:14:35,000 --> 00:14:40,000
+And after that I called to map Masset from collectors' class and past two functions.
+
+198
+00:14:41,000 --> 00:14:47,000
+The first one should create keys, and the second one is a function that can create product values that
+
+199
+00:14:47,000 --> 00:14:49,000
+are associated with a specific case.
+
+200
+00:14:50,000 --> 00:14:56,000
+Taking into account, I don't need to modify a product, I should return the same product.
+
+201
+00:14:56,000 --> 00:15:00,000
+That's why I use identity MASSATA function type here.
+
+202
+00:15:00,000 --> 00:15:08,000
+Identity MassArt returns the same object, does it make sense, the last good example that I want to
+
+203
+00:15:08,000 --> 00:15:15,000
+share with you is map to end and some that I would even say that a group of mass that you will use and
+
+204
+00:15:15,000 --> 00:15:17,000
+these two are just one of many.
+
+205
+00:15:18,000 --> 00:15:23,000
+There are numerous of business cases when they need to process collection of elements and find is a
+
+206
+00:15:23,000 --> 00:15:28,000
+max price or some old values of some field or something similar.
+
+207
+00:15:29,000 --> 00:15:35,000
+To perform these operations, we have to convert our regular stream to in stream or double stream along
+
+208
+00:15:35,000 --> 00:15:36,000
+stream.
+
+209
+00:15:36,000 --> 00:15:44,000
+That's why Stream Type has such masses as map to end, map to double mapped along this massive stage
+
+210
+00:15:44,000 --> 00:15:52,000
+function as an argument then can extract some no value out of current item in stream and these masses
+
+211
+00:15:52,000 --> 00:15:56,000
+rich on specific stream type like any stream that will stream along stream.
+
+212
+00:15:57,000 --> 00:15:59,000
+These types declare new methods.
+
+213
+00:16:00,000 --> 00:16:06,000
+For example, imagine the case when you need to calculate total amount of items of all products in the
+
+214
+00:16:06,000 --> 00:16:08,000
+warehouse aggregate stream.
+
+215
+00:16:08,000 --> 00:16:14,000
+And after that cool map to Inmarsat and parse function that returns into value based on each product,
+
+216
+00:16:15,000 --> 00:16:16,000
+is that clear?
+
+217
+00:16:17,000 --> 00:16:20,000
+And after that I can call some method.
+
+218
+00:16:20,000 --> 00:16:27,000
+This mass at will sum all integers in my end stream that I received after map to Inmarsat invocation.
+
+219
+00:16:28,000 --> 00:16:35,000
+And here I bring the total items amount to consult, by the way, instead of some you can call Max mean
+
+220
+00:16:35,000 --> 00:16:38,000
+average or any other methods you would like.
+
+221
+00:16:38,000 --> 00:16:45,000
+Myside examples from this file, I also prepared a lot of other examples for you, which are the masses,
+
+222
+00:16:45,000 --> 00:16:48,000
+I believe, linked to this file in attachment to this lesson.
+
+223
+00:16:49,000 --> 00:16:54,000
+I want you to investigate these good examples by yourself after the lesson, because technical is a
+
+224
+00:16:54,000 --> 00:16:56,000
+syntax is the same.
+
+225
+00:16:56,000 --> 00:16:58,000
+And you saw already a few examples.
+
+226
+00:16:58,000 --> 00:17:01,000
+Some of the methods are used very rare.
+
+227
+00:17:01,000 --> 00:17:03,000
+Some of them are used more often.
+
+228
+00:17:03,000 --> 00:17:06,000
+We'll talk about the masses in a minute.
+
+229
+00:17:06,000 --> 00:17:12,000
+But remember that you can find any good example with any message from Stream API by searching through
+
+230
+00:17:12,000 --> 00:17:12,000
+this file.
+
+231
+00:17:13,000 --> 00:17:19,000
+Now, when you saw how you can use the masses and stream API, it is only a matter of what that you
+
+232
+00:17:19,000 --> 00:17:20,000
+want to call.
+
+233
+00:17:20,000 --> 00:17:24,000
+We cover all aspects of using stream API from the syntax standpoint.
+
+234
+00:17:24,000 --> 00:17:29,000
+Now we have to learn the masses that you might want to use while working with streams.
+
+235
+00:17:30,000 --> 00:17:32,000
+I want to show you a cheat sheet, I call it.
+
+236
+00:17:32,000 --> 00:17:37,000
+So was the main operations with streams and shared examples.
+
+237
+00:17:37,000 --> 00:17:42,000
+Remember, you can use a cheat sheet in case you forgot something on this slide.
+
+238
+00:17:42,000 --> 00:17:45,000
+You can see how you can create a stream with examples.
+
+239
+00:17:45,000 --> 00:17:47,000
+Some of them we already reviewed.
+
+240
+00:17:47,000 --> 00:17:50,000
+I'm talking about creating a stream from collections and from array.
+
+241
+00:17:51,000 --> 00:17:52,000
+Let's review other options.
+
+242
+00:17:53,000 --> 00:17:56,000
+We can create stream of elements if we want.
+
+243
+00:17:56,000 --> 00:17:59,000
+We can create stream of lines in case we read file.
+
+244
+00:18:00,000 --> 00:18:02,000
+We will learn more about this during the topic.
+
+245
+00:18:02,000 --> 00:18:04,000
+Input output streams in Java.
+
+246
+00:18:05,000 --> 00:18:08,000
+Also, as you can see here, we can create a stream from stream.
+
+247
+00:18:08,000 --> 00:18:11,000
+We can use Stream Builder to add elements.
+
+248
+00:18:11,000 --> 00:18:18,000
+And after that stream also you can invoke parallel stream that would process all elements in different
+
+249
+00:18:18,000 --> 00:18:20,000
+threats of execution.
+
+250
+00:18:20,000 --> 00:18:26,000
+Ensured parallel stream will not always bring you better performance because coordination of multiple
+
+251
+00:18:26,000 --> 00:18:30,000
+threats of execution also requires some calculations.
+
+252
+00:18:30,000 --> 00:18:35,000
+That's why use parallel stream only with the amount of data.
+
+253
+00:18:35,000 --> 00:18:41,000
+It is hard to see what should be considered as Beke because it will depend on the operations you are
+
+254
+00:18:41,000 --> 00:18:43,000
+going to perform and stream.
+
+255
+00:18:43,000 --> 00:18:49,000
+It will also depends on the type of the object that you are going to use and how big it is.
+
+256
+00:18:49,000 --> 00:18:56,000
+I would even say that in case you are not sure whether the parallel stream in some particular case always
+
+257
+00:18:56,000 --> 00:18:58,000
+opt for regular stream in such cases.
+
+258
+00:18:59,000 --> 00:19:05,000
+Also, we can create infinite sequential order stream produced by iterative application of a function
+
+259
+00:19:05,000 --> 00:19:07,000
+to an initial element.
+
+260
+00:19:08,000 --> 00:19:14,000
+Besides that, we can create an infinite sequential stream where each element is generated by the provided
+
+261
+00:19:14,000 --> 00:19:14,000
+supply.
+
+262
+00:19:15,000 --> 00:19:19,000
+In other words, we can pass a function that can generate elements and create a stream.
+
+263
+00:19:20,000 --> 00:19:24,000
+To be honest, I didn't use the last two options very often.
+
+264
+00:19:24,000 --> 00:19:28,000
+So now you know all possible ways to create stream.
+
+265
+00:19:28,000 --> 00:19:29,000
+Let's move on.
+
+266
+00:19:30,000 --> 00:19:33,000
+On this slide, you can see different intermediate methods.
+
+267
+00:19:33,000 --> 00:19:38,000
+Some of them looks familiar to you because we had examples with those masses.
+
+268
+00:19:38,000 --> 00:19:45,000
+You already know when you might want to use filter, map, map to end flatman methods, don't you?
+
+269
+00:19:45,000 --> 00:19:52,000
+You also can use skip method to skip specific number of elements you can call distant Masad to get stream
+
+270
+00:19:52,000 --> 00:19:59,000
+without duplication in case you want to apply consumer function to each element you can call peak MassArt.
+
+271
+00:19:59,000 --> 00:20:05,000
+Usually it is used for debugging purposes, the print element to console to investigate the state of
+
+272
+00:20:05,000 --> 00:20:07,000
+a stream lamet.
+
+273
+00:20:07,000 --> 00:20:11,000
+Masset allows you to limit the number of elements in your stream source.
+
+274
+00:20:12,000 --> 00:20:16,000
+It allows us to source elements in stream by natural ordering.
+
+275
+00:20:16,000 --> 00:20:22,000
+There is also overloaded version of this method that takes Comparator as an argument to define the source
+
+276
+00:20:22,000 --> 00:20:23,000
+and order.
+
+277
+00:20:23,000 --> 00:20:28,000
+Using these intermediate operations, you can do amazing things with data manipulation.
+
+278
+00:20:29,000 --> 00:20:35,000
+Let's look at the next slide and on this slide you can find a list of terminal operations.
+
+279
+00:20:35,000 --> 00:20:42,000
+Today during the demo, you saw collect Masset for each entero find first method returns, the first
+
+280
+00:20:42,000 --> 00:20:43,000
+element from stream.
+
+281
+00:20:43,000 --> 00:20:49,000
+This might be useful in case your source elements in stream and want to take the first elements after
+
+282
+00:20:49,000 --> 00:20:57,000
+sorting, find any MACIT returns, any element from stream patterns that these two methods return object
+
+283
+00:20:57,000 --> 00:20:58,000
+of type optional.
+
+284
+00:20:58,000 --> 00:21:05,000
+This is not the lesson about optional, but ensured optional is a type that is used as a container for
+
+285
+00:21:05,000 --> 00:21:10,000
+objects that may or may not contain and nonono value.
+
+286
+00:21:10,000 --> 00:21:17,000
+Also, these types introduce API to extract value from container or perform as operations in case a
+
+287
+00:21:17,000 --> 00:21:18,000
+container is empty.
+
+288
+00:21:19,000 --> 00:21:27,000
+We can call Count Massud in case we want to get a number of elements in this stream and any match non-match
+
+289
+00:21:27,000 --> 00:21:30,000
+and all march methods take predicate to return.
+
+290
+00:21:30,000 --> 00:21:31,000
+True or false?
+
+291
+00:21:32,000 --> 00:21:38,000
+I believe that it is clear from the method names that any match will return true in case at least one.
+
+292
+00:21:38,000 --> 00:21:45,000
+The elements from streamy, the conditions of predicates that we passed to this massive non-match will
+
+293
+00:21:45,000 --> 00:21:52,000
+return true in case non of elements Margitza Predicate and all March will return true only in case all
+
+294
+00:21:52,000 --> 00:21:56,000
+elements march pre-cut main and maximizers.
+
+295
+00:21:56,000 --> 00:22:03,000
+I believe these are self describing this massive state comparator as an argument for each order.
+
+296
+00:22:03,000 --> 00:22:09,000
+It must is similar to for each Massett, but it also supports order of elements in the stream.
+
+297
+00:22:10,000 --> 00:22:16,000
+Reduce mass performs reduction stream operations that allows us to produce one single result from a
+
+298
+00:22:16,000 --> 00:22:21,000
+sequence of elements in this operation usually take part three participants.
+
+299
+00:22:21,000 --> 00:22:23,000
+They are a regional element.
+
+300
+00:22:24,000 --> 00:22:26,000
+It is also called identity.
+
+301
+00:22:26,000 --> 00:22:29,000
+The second participant is an accumulator.
+
+302
+00:22:29,000 --> 00:22:36,000
+This is a function that takes two parameters, a partial result of the reduction operation and the next
+
+303
+00:22:36,000 --> 00:22:37,000
+element of the string.
+
+304
+00:22:37,000 --> 00:22:40,000
+And the third participant is a combiner.
+
+305
+00:22:40,000 --> 00:22:46,000
+This is a function that is used to combine the partial result of the reduction operation once the reduction
+
+306
+00:22:46,000 --> 00:22:52,000
+is paralyzed or when there is a mismatch between the types of the accumulator arguments and the types
+
+307
+00:22:52,000 --> 00:22:54,000
+of the accumulator implementation.
+
+308
+00:22:55,000 --> 00:23:01,000
+And I know that this can sound not clear, but don't worry about that after this lesson.
+
+309
+00:23:01,000 --> 00:23:03,000
+Take your time to investigate the examples.
+
+310
+00:23:04,000 --> 00:23:10,000
+I didn't show you this example because to be honest, this function is not used super often, really.
+
+311
+00:23:11,000 --> 00:23:16,000
+So take your time to investigate examples and feel free to ask questions in case you have any.
+
+312
+00:23:17,000 --> 00:23:19,000
+That's all what I wanted to share with you today.
+
+313
+00:23:19,000 --> 00:23:24,000
+Now let's recap what we have learned today so that we learned really a lot of things.
+
+314
+00:23:25,000 --> 00:23:26,000
+But let's try to sum it up.
+
+315
+00:23:27,000 --> 00:23:30,000
+We understand what Stream API is now.
+
+316
+00:23:30,000 --> 00:23:36,000
+We know how to create stream, how to use intermediate operations and how to use terminal operations
+
+317
+00:23:37,000 --> 00:23:38,000
+on real life examples.
+
+318
+00:23:38,000 --> 00:23:41,000
+You saw how you can apply your knowledge about Stream API.
+
+319
+00:23:41,000 --> 00:23:47,000
+Also, you got a lot of examples that you can use during the development when you need.
+
+320
+00:23:47,000 --> 00:23:49,000
+And now let me show your homework.
+
+321
+00:23:50,000 --> 00:23:52,000
+You can find multiple tasks here.
+
+322
+00:23:53,000 --> 00:23:59,000
+The important thing in each task is to implement those with the help of Stream API and functional interfaces.
+
+323
+00:24:00,000 --> 00:24:06,000
+You can practice a lot in writing your own lambda expressions and then processing elements in stream
+
+324
+00:24:06,000 --> 00:24:08,000
+read tasks attentively.
+
+325
+00:24:08,000 --> 00:24:15,000
+I edit as much details as I could in each task and remember, in case you have any question gunshy to
+
+326
+00:24:15,000 --> 00:24:17,000
+ask me that.
+
+327
+00:24:17,000 --> 00:24:20,000
+So what I have for you for today, thanks a lot for your attention.
+
+328
+00:24:20,000 --> 00:24:23,000
+Have a great day and see you in the next lesson.
+
diff --git a/23 - Stream API/002 Quiz Functional Programming in Java - Check yourself.html b/23 - Stream API/002 Quiz Functional Programming in Java - Check yourself.html
new file mode 100644
index 0000000000000000000000000000000000000000..996bece0078afc533c6e954996feadd29c59dbe7
--- /dev/null
+++ b/23 - Stream API/002 Quiz Functional Programming in Java - Check yourself.html
@@ -0,0 +1,69 @@
+
+
+
+
+
+ Quiz Functional Programming in Java - Check yourself
+
+
+
+
+
+
+
Quiz Functional Programming in Java - Check yourself
+
Quiz Link: https://forms.gle/uYL6fghm9AJnCQfa9
The quiz doesn’t require you to log in or submit any personal information. Your data privacy is my priority.
The Quiz covers content from the following lessons:
Functional Programming in Java - Overview
Functional Interface, Lambda Functions & Method References
Function & BiFunction: Theory & Practice
Consumer, BiConsumer, Predicate & BiPredicate
Stream API
Quiz Instructions:
This quiz is designed to help you check your understanding of the content from the previous lessons. All questions are based only on material covered in the lessons you've already watched, so there’s no need to worry about unfamiliar topics.
Each question has one correct answer. Select the best answer and click "Submit" when you're ready.
After submitting, you'll see your score. For each question, you earn 1 point.
Click "View Results" to see the explanations for each correct answer. Reviewing these explanations can help reinforce your understanding.
If you score below 70%, I recommend revisiting the previous lessons. However, if the explanations make sense and you’re confident in your understanding, feel free to move on.
If any explanations are unclear, please don’t hesitate to post questions in the Q&A section—I’m here to help!
+
+
+
+
diff --git a/23 - Stream API/external-links.txt b/23 - Stream API/external-links.txt
new file mode 100644
index 0000000000000000000000000000000000000000..4fb498913b447c5938772ccced627fb4cd7f902c
--- /dev/null
+++ b/23 - Stream API/external-links.txt
@@ -0,0 +1,18 @@
+
+001 Documentation-for-java.util.stream-package
+https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/stream/package-summary.html
+
+001 Homework
+https://docs.google.com/document/d/1TLRPMHsciAdeHn8XFWXQYrO3dVGv6b_THev6nKE2ewY/edit?usp=sharing
+
+001 Source-code-All-examples-from-the-lecture
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/functions/streams
+
+001 Homework-Solution-Books-Management
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/oop/hw/books
+
+001 Homework-Solution-Present-Sweets
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/oop/hw/present
+
+001 Homework-Solution-Filter-words-by-length
+https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/methods/hw/FilterStringArray.java
diff --git a/24 - ===== Functional Programming in Java Interview Preparation =====/001 How to be prepared for the interview.html b/24 - ===== Functional Programming in Java Interview Preparation =====/001 How to be prepared for the interview.html
new file mode 100644
index 0000000000000000000000000000000000000000..b6cf01d51f3a1e7617ca256d2b7fabe99fbcfd02
--- /dev/null
+++ b/24 - ===== Functional Programming in Java Interview Preparation =====/001 How to be prepared for the interview.html
@@ -0,0 +1,69 @@
+
+
+
+
+
+ How to be prepared for the interview
+
+
+
+
+
+
+
How to be prepared for the interview
+
I gathered for you the most popular questions during the Java Interview in JAVA FUNCTIONAL PROGRAMMING topic. How you can be prepared for the interview?
Just read the question first. Try to answer the question by yourself. After that, compare your answer with the answer provided. Remember, that this is just a reference to the answer. Because sometimes the topic is big, and you can go really deep with your answer. In case you feel like you don’t understand what the answer is about - feel free to get back in the course and review the relevant section, and relevant lesson one more time.
Also, you are always welcome to ask your questions and I will be happy to answer. I’m sure that these questions will help you to be prepared for the JAVA FUNCTIONAL PROGRAMMING interview. You need to be ready to answer perfectly on these questions.
In case there are questions that you don't know the answers to, please, feel free to check my full and the most complete course "Java From Zero to First Job".
+
+
+
+
diff --git a/24 - ===== Functional Programming in Java Interview Preparation =====/002 Part 1 Java Functional Programming Interview - Questions and Answers.html b/24 - ===== Functional Programming in Java Interview Preparation =====/002 Part 1 Java Functional Programming Interview - Questions and Answers.html
new file mode 100644
index 0000000000000000000000000000000000000000..30c9bfb912b2e6514ee7b13783f70937cfa20546
--- /dev/null
+++ b/24 - ===== Functional Programming in Java Interview Preparation =====/002 Part 1 Java Functional Programming Interview - Questions and Answers.html
@@ -0,0 +1,69 @@
+
+
+
+
+
+ Part 1 Java Functional Programming Interview - Questions and Answers
+
+
+
+
+
+
+
Part 1 Java Functional Programming Interview - Questions and Answers
+
The lambda expression has the following structure:
where
method params - a list of input parameters separated by commas (if there are more than one parameters, they are enclosed in brackets).
operator "->" - serves as a separator between the list of parameters of our method and the body in which its implementation takes place.
lambda expression body - method body, consisting of one or more expressions enclosed in curly braces.
Lambda expressions have access to the variables of the scope in which they are defined. But access is possible only if the variables are effective final, that is, either explicitly have the final modifier, or in case they do not change their value after initialization, if the variable is assigned a value for the second time, the lambda expression causes a compilation error.
Method references are compact lambda expressions that allow you to pass references to methods or constructors. To do this, use the "::" keyword.
Reference methods implement a useful syntax to refer to existing methods or constructors of Java classes or objects (instances). Together with lambda expressions, reference methods make language constructs compact and concise, making it boilerplate.
There are three kinds of method references:
Reference to a static method(ContainingClass::staticMethodName)
Reference to a concrete object method(containingObject::instanceMethodName)
Reference to constructor(ClassName::new), for generics (generics) Class< T >::new.
The System.out::println expression is a reference to the static println method of the out object of the System class, which is equivalent to the x -> System.out.println(x) lambda expression.
A functional interface is one that defines exactly one abstract method.
Java 8 introduced a new @FunctionalInterface annotation to mark an interface as functional, this annotation is used to avoid accidentally adding abstract methods to a functional interface. It's not required, but it's good coding practice.
Functional interfaces allow us to use lambda expressions to instantiate such interfaces.
The best example of a functional interface would be the java.lang.Runnable interface with a single abstract run() method. Note that an interface can include any number of default or static methods and still be functional, because default and static methods are not abstract.
java.util.stream - introduced to support parallelization of computations in streams. Provides the ability to process a sequence of elements by executing one or more operations, which can be performed either sequentially or in parallel. Streams are divided into serial and parallel. The biggest benefit of this is when working with collections.
Operations on a stream are either intermediate or terminal. All intermediate operations return a stream, so we can combine multiple intermediate operations without using a semicolon. Terminal operations return void or a non-stream result.
Most operations of the Stream class that modify a dataset return that dataset as a stream. However, there are situations when you would like to receive data not as a stream, but as a regular collection, for example, ArrayList or HashSet. And for this, the Stream class has a collect method. The method takes as a parameter a conversion function to a collection:
<R,A> R collect(Collector<? super T,A,R> collector)
The R parameter represents the result type of the method, the T parameter is the type of the element in the stream, and the A parameter is the type of the intermediate accumulated data. As a result, the collector parameter represents the function of converting the stream into a collection.
The difference between a Collection (Collection) of data and a stream (Stream) from the new JDK8 is that collections allow you to work with elements individually, while a stream (Stream) does not. For example, with collections, you can add items, remove items, and insert in the middle. A Stream does not allow you to manipulate individual elements from a data set, but instead allows you to perform functions on the data as a whole.
Method void forEach(Consumer<? super T> action) - action is performed for each element. forEach is a terminal operation, used to iterate over each element of the stream.
forEach does not guarantee the sequence of displaying elements in a parallel stream, for this the forEachOrdered method is used - it guarantees the order.
Method <R> Stream<R> map(Function<? super T,? extends R> mapper) - converts elements of type T into elements of type R and returns a stream with elements of R.
map() is an intermediate operation, the method is used to convert elements to another object using the passed function.
Method Stream<T> filter(Predicate<? super T> predicate) - filters elements according to the condition in the predicate. filter is an intermediate operation, used to filter an array through a function.
In fact, filter does not perform filtering, instead it creates a new stream, which, when completed, contains the elements of the original stream that match the given predicate.
Method Stream<T> limit(long maxSize) - leaves only maxSize elements in the stream. limit is an intermediate operation, used to fetch the first maxSize elements of the stream. This method also returns a modified stream that has no more than maxSize elements.
The Stream<T> sorted()/Stream<T> sorted(Comparator<? super T> comparator) method returns a sorted stream. sorted() is an intermediate operation, a method used to sort a stream using the natural order of comparison of its elements. There is also a second sorted() method that takes either a Comparable instance or its corresponding lambda expression.
To make a normal serial stream parallel, call the parallel method on the Stream object.
Alternatively, you can also use the parallelStream() method of the Collection interface to create a parallel stream from a collection.
At the same time, if the working machine is not multi-core, then the thread will be executed as serial.
+
+
+
+
diff --git a/24 - ===== Functional Programming in Java Interview Preparation =====/003 Part 2 Java Functional Programming Interview - Questions and Answers.html b/24 - ===== Functional Programming in Java Interview Preparation =====/003 Part 2 Java Functional Programming Interview - Questions and Answers.html
new file mode 100644
index 0000000000000000000000000000000000000000..39f17dbc7f3fbca6cc7788ec820be262ebc214fb
--- /dev/null
+++ b/24 - ===== Functional Programming in Java Interview Preparation =====/003 Part 2 Java Functional Programming Interview - Questions and Answers.html
@@ -0,0 +1,69 @@
+
+
+
+
+
+ Part 2 Java Functional Programming Interview - Questions and Answers
+
+
+
+
+
+
+
Part 2 Java Functional Programming Interview - Questions and Answers
+
Represents an operation that takes two input parameters and returns no result.
It is a function that takes two arguments and returns a result.
Represents an operation on two operands of the same type, performs a binary operation on them, and returns a result of the same type as the operands.
Represents a predicate (boolean function) of two arguments.
Represents a boolean result provider.
Represents an operation that takes one input argument, performs some action on an object of type T, and returns nothing.
Represents an operation on two operands of type double, returns a result of type double.
Represents an operation that takes one double argument and does not return a result.
Represents a function that takes one double argument and returns a result.
Represents a predicate (boolean function) of one double argument.
Represents the provider of double results.
It is a function that takes one argument of type double and returns the result of type int.
Represents a function that takes one argument of type double and returns a result of type long.
Represents an operation on one argument of double type, returns a result of type double.
Represents a transition function from an object of type T to an object of type R.
Represents an operation on two operands of type int, returns a result of type int.
Represents an operation that takes a single int argument and returns no result.
Represents an operation that takes one int argument and returns a result.
Represents a predicate (boolean function) of one int argument.
Represents an int result provider.
Represents a function that takes one argument of type int and returns a result of type double.
Represents a function that takes one argument of type int and returns a result of type long.
Represents an operation on a single argument of type int, returns a result of type int.
Represents an operation on two operands of type long, returns a result of type long.
Represents an operation that takes one long argument and does not return a result.
Represents a function that takes one long argument and returns a result.
Represents a predicate (boolean function) of one argument of type long.
Represents a provider of long results.
Represents a function that takes one argument of type long and returns a result of type double.
Represents a function that takes one argument of type long and returns a result of type int.
Represents an operation on a single argument of type long, returns a result of type long.
Represents an operation that takes one argument of type object and a second of type double, and does not return a result.
Represents an operation that takes one argument of type object and a second of type int and does not return a result.
Represents an operation that takes one argument of type object and a second of type long, and does not return a result.
Represents a predicate (boolean function) of one argument.
Represents a results provider.
It is a function that takes two arguments and returns a result of double type.
It is a function that takes one argument and returns a double result.
It is a function that takes two arguments and returns an int result.
It is a function that takes one argument and returns an int result.
It is a function that takes two arguments and returns a long result.
It is a function that takes one argument and returns a result of type long.
Represents an operation on a single operand, returns a result of the same type as the operand.
+
+
+
+
diff --git a/25 - Input and Output Streams in Java/001 Homework.url b/25 - Input and Output Streams in Java/001 Homework.url
new file mode 100644
index 0000000000000000000000000000000000000000..8c8fa0b8828d22a69382c7d299ac483f30b8b2f3
--- /dev/null
+++ b/25 - Input and Output Streams in Java/001 Homework.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://docs.google.com/document/d/12mpGjQti9SwYrCS-0RU-WNYtEQCKSFwjgiCS8iKDnTw/edit?usp=sharing
\ No newline at end of file
diff --git a/25 - Input and Output Streams in Java/001 Input and Output Streams in Java_en.srt b/25 - Input and Output Streams in Java/001 Input and Output Streams in Java_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..5552be72330cd97b2ceda62c8cbc981e56a1f4e1
--- /dev/null
+++ b/25 - Input and Output Streams in Java/001 Input and Output Streams in Java_en.srt
@@ -0,0 +1,1900 @@
+1
+00:00:05,000 --> 00:00:06,000
+Hello, Jim.
+
+2
+00:00:06,000 --> 00:00:11,000
+They were going to loan with you how to work with inputs and outputs streams in Java.
+
+3
+00:00:11,000 --> 00:00:14,000
+We will start our lesson from learning how to work with files in Java.
+
+4
+00:00:15,000 --> 00:00:22,000
+We learned today how to create byte and input streams and also will create byte and charter output streams
+
+5
+00:00:22,000 --> 00:00:23,000
+on real examples.
+
+6
+00:00:23,000 --> 00:00:27,000
+You are going to see how to work with files with the help of Java today.
+
+7
+00:00:27,000 --> 00:00:32,000
+You are going to learn how to close resources and how to use blog driveway's resources.
+
+8
+00:00:32,000 --> 00:00:37,000
+After today's lesson, you will understand how to use different encoding while reading and writing to
+
+9
+00:00:37,000 --> 00:00:39,000
+file at the end of the lesson.
+
+10
+00:00:39,000 --> 00:00:42,000
+We will talk about classes and interfaces from Joany Your package.
+
+11
+00:00:42,000 --> 00:00:46,000
+I'll show you how you can process files with the help of Stream API.
+
+12
+00:00:46,000 --> 00:00:50,000
+You are going to learn what Buffer's dreams are and how to work with them.
+
+13
+00:00:50,000 --> 00:00:55,000
+Also, I'll share with you tasks that will help you to practice your skills of working with streams.
+
+14
+00:00:55,000 --> 00:01:03,000
+Let's start Java IO package is about reading data from a data source and writing of raw data to a destination.
+
+15
+00:01:03,000 --> 00:01:05,000
+There are various or data destinations.
+
+16
+00:01:05,000 --> 00:01:12,000
+Some of them are files by network, connections in memory buffers and so on.
+
+17
+00:01:12,000 --> 00:01:18,000
+Work with different data sources are similar from the application programming interface standpoint.
+
+18
+00:01:18,000 --> 00:01:24,000
+That's why I suggest to review all examples of input output streams while working with files.
+
+19
+00:01:24,000 --> 00:01:28,000
+We have to learn what files are and how to work with files.
+
+20
+00:01:28,000 --> 00:01:35,000
+To be honest, input output streams topic in Java is one of the most unstructured, a lot of packages,
+
+21
+00:01:35,000 --> 00:01:38,000
+a lot of Iraqis, a lot of classes and so on.
+
+22
+00:01:38,000 --> 00:01:43,000
+That's why I believe that this topic is the best way to learn it by example.
+
+23
+00:01:44,000 --> 00:01:48,000
+I prepared a lot of my files to help you understand the topic better.
+
+24
+00:01:48,000 --> 00:01:49,000
+Let me open the eclipse.
+
+25
+00:01:50,000 --> 00:01:55,000
+As I already mentioned, I think it is better to start from over here what files are and how to work
+
+26
+00:01:55,000 --> 00:01:56,000
+with them from Java.
+
+27
+00:01:57,000 --> 00:02:01,000
+I wrote a program here, let me run it and explore its output together with you.
+
+28
+00:02:02,000 --> 00:02:05,000
+In this example, we'll review time from packaged Java Io.
+
+29
+00:02:06,000 --> 00:02:08,000
+We have type to represent file.
+
+30
+00:02:08,000 --> 00:02:14,000
+I can easily create file object by calling constructor and patterns the file name to constructor and
+
+31
+00:02:14,000 --> 00:02:19,000
+then want to pay attention that we didn't create a file in file system.
+
+32
+00:02:19,000 --> 00:02:25,000
+We have just created file instant's and now we can call mascot's on this object that will help us to
+
+33
+00:02:25,000 --> 00:02:27,000
+create files in working directory.
+
+34
+00:02:27,000 --> 00:02:32,000
+The string that we gave to constructor is converted into abstract Bazzani.
+
+35
+00:02:33,000 --> 00:02:36,000
+I can create a catalog using this object.
+
+36
+00:02:36,000 --> 00:02:40,000
+In other words, I can create a folder by calling M Khadir method.
+
+37
+00:02:40,000 --> 00:02:46,000
+In case you want to create a hierarchy of folders, you can specify directories name using file past
+
+38
+00:02:46,000 --> 00:02:49,000
+separator operator and call mkdir smashup.
+
+39
+00:02:49,000 --> 00:02:56,000
+But creating programs with Java will create cross platform applications and we should use platform independent
+
+40
+00:02:56,000 --> 00:02:57,000
+characters.
+
+41
+00:02:57,000 --> 00:03:03,000
+Class file contains platform independent files separate and Kendzior returns.
+
+42
+00:03:03,000 --> 00:03:04,000
+True or false?
+
+43
+00:03:04,000 --> 00:03:07,000
+You can build a logic around this API here.
+
+44
+00:03:07,000 --> 00:03:12,000
+I will print the console file separate in one operating systems.
+
+45
+00:03:12,000 --> 00:03:13,000
+It is a backslash.
+
+46
+00:03:13,000 --> 00:03:15,000
+In other it is a slash.
+
+47
+00:03:15,000 --> 00:03:21,000
+Java will determine what operating system is used and will provide you with platform specific files.
+
+48
+00:03:21,000 --> 00:03:26,000
+Separate file also provides us with a constant firebase separator.
+
+49
+00:03:26,000 --> 00:03:29,000
+Do remember when we configure Jabel Normal computer?
+
+50
+00:03:29,000 --> 00:03:31,000
+We are to set environment.
+
+51
+00:03:31,000 --> 00:03:39,000
+Variables would change the value of past variable and as a separate that we use semicolon that is specific
+
+52
+00:03:39,000 --> 00:03:40,000
+to Windows operating system.
+
+53
+00:03:40,000 --> 00:03:45,000
+Separate that and you can see it in console in other operating system.
+
+54
+00:03:45,000 --> 00:03:51,000
+It could be a column here, by the way, talking about plot from independent characters.
+
+55
+00:03:51,000 --> 00:03:57,000
+I want to pay attention to line separate in some operating systems line separate.
+
+56
+00:03:57,000 --> 00:04:03,000
+That is a combination of characters like carriage return and new line in other operating systems.
+
+57
+00:04:03,000 --> 00:04:05,000
+It is just a new line character.
+
+58
+00:04:05,000 --> 00:04:12,000
+So whenever you need to express a new line, for example, in cases when you prepare text that should
+
+59
+00:04:12,000 --> 00:04:17,000
+be read into the file, I recommend you to use Mass from system class with name lines separator.
+
+60
+00:04:18,000 --> 00:04:22,000
+Now imagine that you have to create not directory, but just a file.
+
+61
+00:04:23,000 --> 00:04:30,000
+Imagine that content manager of our online store wants to do an expert of all products to the specific
+
+62
+00:04:30,000 --> 00:04:33,000
+file we have to create file for him.
+
+63
+00:04:33,000 --> 00:04:39,000
+At first we create file object and after that we create file by calling in mass.
+
+64
+00:04:39,000 --> 00:04:45,000
+It creates new file after this letter and I recommend you to open source code of the file class and
+
+65
+00:04:45,000 --> 00:04:47,000
+explore all of its methods.
+
+66
+00:04:48,000 --> 00:04:53,000
+But I want to show you your methods that may come in handy while working with files.
+
+67
+00:04:53,000 --> 00:04:59,000
+For example, you might always check was a file exists because it exists MassArt or you can check if
+
+68
+00:04:59,000 --> 00:05:01,000
+s specific file is directory.
+
+69
+00:05:02,000 --> 00:05:04,000
+When you need this, you are going to have.
+
+70
+00:05:04,000 --> 00:05:10,000
+Homework, where you would need to implement the program to solve real life case, you can build the
+
+71
+00:05:10,000 --> 00:05:17,000
+logic of iterating and navigate in your file system by identifying whether some specific item is a directory
+
+72
+00:05:17,000 --> 00:05:17,000
+or a file.
+
+73
+00:05:18,000 --> 00:05:24,000
+In case this item is a directory and you want iterate over all elements, you have to get files from
+
+74
+00:05:24,000 --> 00:05:27,000
+this directory to do this.
+
+75
+00:05:27,000 --> 00:05:29,000
+You can call list files Macit.
+
+76
+00:05:29,000 --> 00:05:33,000
+It will return array of files and you can work with the file array.
+
+77
+00:05:33,000 --> 00:05:37,000
+As with any other array, you can iterate over it if you need.
+
+78
+00:05:38,000 --> 00:05:43,000
+You can get absolute parts of the file by calling it absolute Balmaceda.
+
+79
+00:05:43,000 --> 00:05:47,000
+Also, you can check whether files that you have is executable.
+
+80
+00:05:48,000 --> 00:05:54,000
+For example, files with a DOT board extension, executable files on the Unix systems.
+
+81
+00:05:54,000 --> 00:06:01,000
+There are shell scripts with Dot S.H. extension, those executable too similar to the way you can check
+
+82
+00:06:01,000 --> 00:06:02,000
+what a specific item is.
+
+83
+00:06:02,000 --> 00:06:03,000
+A directory or not.
+
+84
+00:06:04,000 --> 00:06:08,000
+You can check if a specific item is a file by Colon is file Macit.
+
+85
+00:06:09,000 --> 00:06:15,000
+Sometimes the hidden files in the file system, for example, get folder of our local repository is
+
+86
+00:06:15,000 --> 00:06:16,000
+a hidden by default.
+
+87
+00:06:17,000 --> 00:06:19,000
+You can check it by colon is hidden last.
+
+88
+00:06:19,000 --> 00:06:20,000
+Is it clear.
+
+89
+00:06:21,000 --> 00:06:26,000
+Feel free to press a pause to review these matters and make sure that you understood them.
+
+90
+00:06:26,000 --> 00:06:32,000
+Also, I want to remind you that you are always welcome to ask any questions and Q&A section.
+
+91
+00:06:32,000 --> 00:06:38,000
+If you understood the masses that we have just reviewed, I suggest to move further, you know, just
+
+92
+00:06:38,000 --> 00:06:41,000
+Solly's files, MassArt, but it is overloaded.
+
+93
+00:06:41,000 --> 00:06:44,000
+Let me open the source code of this version of the Massett.
+
+94
+00:06:45,000 --> 00:06:48,000
+And right near this method we have another one.
+
+95
+00:06:48,000 --> 00:06:54,000
+This method takes file filter as an argument to filter files and return only files that that means the
+
+96
+00:06:54,000 --> 00:07:01,000
+condition that is specified in file filter lets open file filter to understand this interface better.
+
+97
+00:07:01,000 --> 00:07:07,000
+And here and the source code we can see that file filter is a functional interface assumes that by this
+
+98
+00:07:07,000 --> 00:07:13,000
+moment and now of course you already know functional programming and can understand what functional
+
+99
+00:07:13,000 --> 00:07:14,000
+interface annotation is.
+
+100
+00:07:15,000 --> 00:07:22,000
+Just to remind you, this annotation means that the interface is only one aspect Masset and we can use
+
+101
+00:07:22,000 --> 00:07:25,000
+is a massive reference or lambda function to implement this type.
+
+102
+00:07:26,000 --> 00:07:33,000
+Indeed, file filter has only one abasic Masset with name except the text file as an argument and should
+
+103
+00:07:33,000 --> 00:07:35,000
+return is a true or false.
+
+104
+00:07:35,000 --> 00:07:42,000
+Let's get back to our demo file was filed, for example, here in the example you can see that I created
+
+105
+00:07:42,000 --> 00:07:47,000
+Lambda Functions that meets the definition of accept Masset from file filter interface.
+
+106
+00:07:47,000 --> 00:07:49,000
+It takes file object and returns.
+
+107
+00:07:49,000 --> 00:07:56,000
+True or false based on it, you can see that I get filename and after that I check with a file.
+
+108
+00:07:56,000 --> 00:07:58,000
+Name is ended with Java.
+
+109
+00:07:58,000 --> 00:08:02,000
+This lambda function will return me only Java source code files.
+
+110
+00:08:03,000 --> 00:08:04,000
+Does it make sense?
+
+111
+00:08:04,000 --> 00:08:08,000
+Let me run this program to execute all the code that we have just reviewed.
+
+112
+00:08:08,000 --> 00:08:16,000
+By the way, after execution of this program, all folders are created here and here is our result since
+
+113
+00:08:16,000 --> 00:08:18,000
+we file that we also created in our program.
+
+114
+00:08:18,000 --> 00:08:26,000
+So now you can understand that the path that we specified for file here is relative and it is relative
+
+115
+00:08:26,000 --> 00:08:27,000
+to our Java project.
+
+116
+00:08:28,000 --> 00:08:30,000
+You can use absolute powers if you want.
+
+117
+00:08:30,000 --> 00:08:35,000
+The absolute pass on Windows would include your disk C and all the folders.
+
+118
+00:08:36,000 --> 00:08:39,000
+For example, here you can see absolute file pass.
+
+119
+00:08:40,000 --> 00:08:45,000
+Usually in your programs you don't want to specify absolute pass y.
+
+120
+00:08:45,000 --> 00:08:50,000
+You have to understand that your program is going to be executed on different computers and on different
+
+121
+00:08:50,000 --> 00:08:54,000
+servers and file system will look differently on each computer.
+
+122
+00:08:55,000 --> 00:08:59,000
+For example, on Unix like operating system, there is no use C at all.
+
+123
+00:09:00,000 --> 00:09:01,000
+Can you understand that?
+
+124
+00:09:01,000 --> 00:09:06,000
+That's why in real life you would usually use relative to your project.
+
+125
+00:09:06,000 --> 00:09:08,000
+Just makes sense cuz.
+
+126
+00:09:09,000 --> 00:09:16,000
+Now, I want to share with you and as a way to manipulate files besides Java, I hope there is also
+
+127
+00:09:16,000 --> 00:09:17,000
+Java new package.
+
+128
+00:09:18,000 --> 00:09:21,000
+It is called as new output input streams.
+
+129
+00:09:21,000 --> 00:09:28,000
+That's why it has end letter in the name Unions and National Review and parallel classes and types from
+
+130
+00:09:28,000 --> 00:09:29,000
+Java I.
+
+131
+00:09:29,000 --> 00:09:31,000
+O Package and classes and types from Jouni.
+
+132
+00:09:31,000 --> 00:09:32,000
+A package.
+
+133
+00:09:32,000 --> 00:09:36,000
+From the practical side, I can say that classes from both.
+
+134
+00:09:36,000 --> 00:09:39,000
+I mean I o and newer packages are used.
+
+135
+00:09:40,000 --> 00:09:42,000
+There are no specific preferences.
+
+136
+00:09:42,000 --> 00:09:46,000
+It is just a matter of APIs and how you would like to work with streams.
+
+137
+00:09:47,000 --> 00:09:50,000
+There is a way to do the same things but with different classes.
+
+138
+00:09:50,000 --> 00:09:57,000
+And we as developers should be aware of different interfaces in Java because different APIs would use
+
+139
+00:09:57,000 --> 00:09:58,000
+different types.
+
+140
+00:09:59,000 --> 00:10:04,000
+Let me open another file with examples that will help you to understand how you can manipulate with
+
+141
+00:10:04,000 --> 00:10:04,000
+files.
+
+142
+00:10:04,000 --> 00:10:10,000
+With the help of Java new package in your package, there is one important difference.
+
+143
+00:10:10,000 --> 00:10:15,000
+The concept and all API is built around Naza abstraction.
+
+144
+00:10:15,000 --> 00:10:16,000
+It is name POS.
+
+145
+00:10:17,000 --> 00:10:19,000
+You don't have a file like in Java I o package.
+
+146
+00:10:20,000 --> 00:10:27,000
+What you can do is to manipulate with a resource by its boss to create path object we have to use first
+
+147
+00:10:27,000 --> 00:10:33,000
+class was asked at the end and static method get let me open the source code of POS class.
+
+148
+00:10:34,000 --> 00:10:37,000
+This specific method takes verbal arguments.
+
+149
+00:10:37,000 --> 00:10:44,000
+You can pass one string that contains file pass separators, but also you can pass multiple strings
+
+150
+00:10:44,000 --> 00:10:51,000
+to indicate in the directories you can see that this is Ovalau, that we also have another version of
+
+151
+00:10:51,000 --> 00:10:53,000
+it to pass your right object.
+
+152
+00:10:53,000 --> 00:10:59,000
+But in my opinion, this version of get matched with variable string arguments is more popular.
+
+153
+00:10:59,000 --> 00:11:04,000
+Let's get back to the demo file and I will show you Boss API in your package.
+
+154
+00:11:04,000 --> 00:11:11,000
+There is files class that contains a lot of masses to work with files and the same as other classes
+
+155
+00:11:11,000 --> 00:11:11,000
+from John.
+
+156
+00:11:11,000 --> 00:11:19,000
+Your package, it uses POS type in its own API, the same operations that we did with the file object.
+
+157
+00:11:19,000 --> 00:11:22,000
+In the previous example, we can do with the help of files class.
+
+158
+00:11:23,000 --> 00:11:29,000
+For example, we can check whether the file behind this passes the directory or it is a regular file.
+
+159
+00:11:29,000 --> 00:11:33,000
+We can create a hierarchy of directories by and create directories.
+
+160
+00:11:33,000 --> 00:11:36,000
+Masset, you can create a file when you want.
+
+161
+00:11:36,000 --> 00:11:38,000
+We can also delete directory bytes.
+
+162
+00:11:38,000 --> 00:11:44,000
+But as you can see, you can do pretty much everything you want to do with files, with the help of
+
+163
+00:11:44,000 --> 00:11:45,000
+files class.
+
+164
+00:11:46,000 --> 00:11:52,000
+What I would recommend you also to do is to open the source code of files class and to review all of
+
+165
+00:11:52,000 --> 00:11:53,000
+its methods.
+
+166
+00:11:53,000 --> 00:11:59,000
+I believe you are smart enough already to read the documentation and to understand what each method
+
+167
+00:11:59,000 --> 00:12:04,000
+is all about, because we did that with other classes and you know how to do this.
+
+168
+00:12:04,000 --> 00:12:11,000
+And there is not so much sense to go over each method and with documentation outloud also take into
+
+169
+00:12:11,000 --> 00:12:14,000
+account we reviewed the most popular methods in my opinion.
+
+170
+00:12:14,000 --> 00:12:18,000
+So just take your time at home to review the source code of files.
+
+171
+00:12:18,000 --> 00:12:24,000
+Class by yourself, meanwhile, will go further and I will explain you the structure of input and output
+
+172
+00:12:24,000 --> 00:12:26,000
+streams now.
+
+173
+00:12:26,000 --> 00:12:30,000
+And once you understand the hierarchy of all types in Java I.
+
+174
+00:12:30,000 --> 00:12:37,000
+O package, we have two main Iraqis, Zaya Iraqiya, by streams and character streams.
+
+175
+00:12:37,000 --> 00:12:39,000
+What is the difference between them?
+
+176
+00:12:39,000 --> 00:12:43,000
+My streams can work with data with size eight bits.
+
+177
+00:12:43,000 --> 00:12:44,000
+That is one byte.
+
+178
+00:12:45,000 --> 00:12:49,000
+So all reading and writing operations work was a bit.
+
+179
+00:12:49,000 --> 00:12:56,000
+These types were created since Java creation and after that time that can process data of two bytes
+
+180
+00:12:56,000 --> 00:12:57,000
+were created.
+
+181
+00:12:57,000 --> 00:13:03,000
+Now there is a possibility to process Unicode characters and describe them in sixteen bits.
+
+182
+00:13:03,000 --> 00:13:06,000
+That is two bytes all possible.
+
+183
+00:13:06,000 --> 00:13:12,000
+The Unicode characters, definitely characters streams are used to work with text data in case you need
+
+184
+00:13:12,000 --> 00:13:14,000
+to read or write text data.
+
+185
+00:13:14,000 --> 00:13:20,000
+It is recommended to use characters streams to ensure that you can read all characters from the file
+
+186
+00:13:21,000 --> 00:13:22,000
+on the other end.
+
+187
+00:13:22,000 --> 00:13:25,000
+But streams are widely used in reading and writing resources.
+
+188
+00:13:26,000 --> 00:13:32,000
+For example, in case you want to store image in your file system, user uploaded and Avatar and you
+
+189
+00:13:32,000 --> 00:13:39,000
+want to store profile image on the file system of your server, you can transform this image and bitstream
+
+190
+00:13:39,000 --> 00:13:43,000
+and store it as a sequence of bytes on your file system and when it will be needed.
+
+191
+00:13:44,000 --> 00:13:47,000
+You can read stream of bytes to restore the image.
+
+192
+00:13:47,000 --> 00:13:48,000
+Does it make sense?
+
+193
+00:13:49,000 --> 00:13:56,000
+On the top of the bitstream, Iraqis are to abstract classes, inputs and outputs stream and there are
+
+194
+00:13:56,000 --> 00:14:03,000
+dozens of implementations classes like file input stream, Vitara input stream, object, input stream
+
+195
+00:14:03,000 --> 00:14:04,000
+and Osas.
+
+196
+00:14:04,000 --> 00:14:08,000
+If we talk about classes that extends output stream, it is worth Dimanche on such.
+
+197
+00:14:08,000 --> 00:14:16,000
+Losses as file output stream by output stream, object's output stream and osos on the top of character
+
+198
+00:14:16,000 --> 00:14:19,000
+stream, Iraqis are also to abstract classes.
+
+199
+00:14:19,000 --> 00:14:26,000
+They are reader and writer and you can see on the slides that multiple classes extended zis to all classes
+
+200
+00:14:26,000 --> 00:14:30,000
+usually have appropriate suffix reader or writer.
+
+201
+00:14:31,000 --> 00:14:33,000
+Take a look at this Iraqi press.
+
+202
+00:14:33,000 --> 00:14:38,000
+Pause for a second and make sure the slide looks clear and logical to you.
+
+203
+00:14:38,000 --> 00:14:41,000
+If you think you understood this, let's move on.
+
+204
+00:14:41,000 --> 00:14:44,000
+Let me now show you how you can work with inputs and outputs.
+
+205
+00:14:44,000 --> 00:14:45,000
+Streams.
+
+206
+00:14:46,000 --> 00:14:51,000
+I will share with you this demo file and I want you to execute these examples on your computer separately
+
+207
+00:14:52,000 --> 00:14:53,000
+and would investigate the result.
+
+208
+00:14:54,000 --> 00:14:59,000
+This will help you better understand how input and output streams work right now.
+
+209
+00:14:59,000 --> 00:15:02,000
+I walk you through these examples to share with you my thoughts.
+
+210
+00:15:03,000 --> 00:15:08,000
+At the beginning of our program, we specify a file pass that will be used as a test directory for the
+
+211
+00:15:08,000 --> 00:15:10,000
+sake of our examples.
+
+212
+00:15:10,000 --> 00:15:15,000
+And also we have here tags that contains different characters, including Cyrillic characters.
+
+213
+00:15:15,000 --> 00:15:18,000
+This will help us to understand encoding examples.
+
+214
+00:15:18,000 --> 00:15:23,000
+Let's start our first example is right, text or file.
+
+215
+00:15:23,000 --> 00:15:24,000
+With the help of BitStream.
+
+216
+00:15:25,000 --> 00:15:28,000
+We have this method here that takes path and string.
+
+217
+00:15:28,000 --> 00:15:30,000
+Let's investigate the source code.
+
+218
+00:15:30,000 --> 00:15:32,000
+I have tried finally block here.
+
+219
+00:15:32,000 --> 00:15:33,000
+Why do I need it?
+
+220
+00:15:34,000 --> 00:15:40,000
+It is a rule of thumb to close their sources once you use them because having multiple resources open
+
+221
+00:15:41,000 --> 00:15:43,000
+will make it harm to your application.
+
+222
+00:15:43,000 --> 00:15:50,000
+This could lead to resource leak to close any of inputs and outputs streams we have to call close Masset
+
+223
+00:15:50,000 --> 00:15:54,000
+on the resource to have access to output stream reference.
+
+224
+00:15:55,000 --> 00:16:02,000
+I declare it outside of the try block inside the trial block and create an instance of file output stream
+
+225
+00:16:02,000 --> 00:16:04,000
+and specify parts to the file.
+
+226
+00:16:04,000 --> 00:16:10,000
+After that, I get bytes from the string and I call write method to write bytes to the file.
+
+227
+00:16:11,000 --> 00:16:13,000
+After I did, everything I need was a resource.
+
+228
+00:16:13,000 --> 00:16:15,000
+I close it and finally block.
+
+229
+00:16:16,000 --> 00:16:18,000
+That's why I have such construction.
+
+230
+00:16:18,000 --> 00:16:20,000
+Let's proceed with the next example.
+
+231
+00:16:21,000 --> 00:16:24,000
+In the next example, there are a few more things to learn.
+
+232
+00:16:24,000 --> 00:16:28,000
+First of all, then all the construction to close the resources.
+
+233
+00:16:28,000 --> 00:16:30,000
+It is called Trivers Resources Block.
+
+234
+00:16:31,000 --> 00:16:32,000
+Let's go line by line.
+
+235
+00:16:32,000 --> 00:16:39,000
+I write right keyword and after that in parentheses, I specify resources that should be closed automatically
+
+236
+00:16:40,000 --> 00:16:42,000
+outside of the Trivers resources block.
+
+237
+00:16:42,000 --> 00:16:47,000
+All types that implements closable interface can be used in this block.
+
+238
+00:16:47,000 --> 00:16:53,000
+Let me open the source code of file output stream and here you can see that it extends output stream
+
+239
+00:16:53,000 --> 00:16:56,000
+type that in turn implements closable interface.
+
+240
+00:16:56,000 --> 00:17:01,000
+That's why this type can be placed inside thrivers resources block.
+
+241
+00:17:01,000 --> 00:17:05,000
+The next thing to learn here is using the word keyword.
+
+242
+00:17:05,000 --> 00:17:12,000
+This is exactly the case when using the keyword is justified because this is just local variable that
+
+243
+00:17:12,000 --> 00:17:15,000
+is going to be used right after its declaration.
+
+244
+00:17:15,000 --> 00:17:21,000
+That's why there is no need to declare abstract type of this variable and it can be the same as a specific
+
+245
+00:17:21,000 --> 00:17:21,000
+type.
+
+246
+00:17:22,000 --> 00:17:28,000
+For example, there is no need for me to specify output stream type for variable if I want to use buffer
+
+247
+00:17:28,000 --> 00:17:31,000
+output stream and all of its features and masses.
+
+248
+00:17:32,000 --> 00:17:38,000
+Let's talk about the next thing you can see that I create object of file output stream and Robert with
+
+249
+00:17:38,000 --> 00:17:46,000
+a type Barford output stream later one architectural partners, you are going to learn that there is
+
+250
+00:17:46,000 --> 00:17:50,000
+a create structural partan that is implemented just like this.
+
+251
+00:17:51,000 --> 00:17:55,000
+You can add new features to the object by wrapping it with new type.
+
+252
+00:17:55,000 --> 00:18:00,000
+Literally, you pass the one object as an argument to the constructor of another one.
+
+253
+00:18:01,000 --> 00:18:05,000
+In this particular case, we are adding feature of buffer writing.
+
+254
+00:18:05,000 --> 00:18:08,000
+What is a buffer buffer in the computer?
+
+255
+00:18:08,000 --> 00:18:15,000
+Science is a region of physical memory storage used to temporarily store data while it is being moved
+
+256
+00:18:15,000 --> 00:18:22,000
+from one place to another buffer to either use memory efficiently by writing everything to the buffer
+
+257
+00:18:22,000 --> 00:18:26,000
+first and after that right and everything to the target at once.
+
+258
+00:18:27,000 --> 00:18:33,000
+This is considered more efficient than to perform right operations to the destination file back by byte.
+
+259
+00:18:34,000 --> 00:18:38,000
+Can you understand now why we might want to use buffer inputs and outputs streams?
+
+260
+00:18:39,000 --> 00:18:46,000
+And now I can write all string to the file outside of the TRIVERS resources block buffer is flushed
+
+261
+00:18:46,000 --> 00:18:47,000
+automatically.
+
+262
+00:18:48,000 --> 00:18:51,000
+There is one more thing you have to know about the buffer.
+
+263
+00:18:51,000 --> 00:18:58,000
+It is flashed automatically into cases when maximum size of the buffer is reached and the second case
+
+264
+00:18:58,000 --> 00:18:59,000
+is when stream is closed.
+
+265
+00:19:00,000 --> 00:19:06,000
+That means that in case you wrote, just not so much information to the buffer and you forgot to close
+
+266
+00:19:06,000 --> 00:19:06,000
+the buffer.
+
+267
+00:19:07,000 --> 00:19:10,000
+You will write Nassan to the file in the next Masset.
+
+268
+00:19:10,000 --> 00:19:12,000
+You can see exactly this case.
+
+269
+00:19:13,000 --> 00:19:19,000
+Let me comment on matters that are called after this one and now I can run the program.
+
+270
+00:19:20,000 --> 00:19:25,000
+Now, when program is executed, I want to check output file just as directory.
+
+271
+00:19:26,000 --> 00:19:32,000
+And here is how a demo text file you can see that is empty because Buffer is not flushed.
+
+272
+00:19:33,000 --> 00:19:35,000
+Now let's get back to our demo file.
+
+273
+00:19:35,000 --> 00:19:39,000
+And I vividly called Flash Masset to phlogiston buffer.
+
+274
+00:19:39,000 --> 00:19:41,000
+I execute the program one more time.
+
+275
+00:19:42,000 --> 00:19:45,000
+And if we would look to our output file where.
+
+276
+00:19:45,000 --> 00:19:52,000
+And to find that the tax was successfully written and you understand now what Buffer is, you can investigate
+
+277
+00:19:52,000 --> 00:19:54,000
+the source code to learn more.
+
+278
+00:19:54,000 --> 00:20:00,000
+For example, let me open bar for output stream and to explore its close method together with you.
+
+279
+00:20:01,000 --> 00:20:06,000
+There is no closed Manhattan buffer at output stream because it is implemented in the parent type.
+
+280
+00:20:07,000 --> 00:20:10,000
+Lets open parent type and find close massive here.
+
+281
+00:20:10,000 --> 00:20:11,000
+Awesome.
+
+282
+00:20:11,000 --> 00:20:12,000
+Here it is.
+
+283
+00:20:13,000 --> 00:20:18,000
+And you can see that during the closing of this resource flash, it is called automatically.
+
+284
+00:20:18,000 --> 00:20:25,000
+That is exactly the reason why we can see that text was written in the file in case we use Buffer,
+
+285
+00:20:25,000 --> 00:20:32,000
+its output stream with strivings resources block because close method is called automatically for all
+
+286
+00:20:32,000 --> 00:20:34,000
+resources specified in Trie lock.
+
+287
+00:20:35,000 --> 00:20:36,000
+Does it make more sense now?
+
+288
+00:20:36,000 --> 00:20:37,000
+Great.
+
+289
+00:20:37,000 --> 00:20:38,000
+Let's move on.
+
+290
+00:20:38,000 --> 00:20:42,000
+And before we proceed, let me comment on other matters.
+
+291
+00:20:42,000 --> 00:20:42,000
+Cool.
+
+292
+00:20:43,000 --> 00:20:47,000
+We'll review the next examples a little bit faster because they are similar.
+
+293
+00:20:47,000 --> 00:20:52,000
+These examples shows us how to write to the file with character streams.
+
+294
+00:20:52,000 --> 00:20:53,000
+We just create file, right?
+
+295
+00:20:53,000 --> 00:20:55,000
+An object that extends right to type.
+
+296
+00:20:56,000 --> 00:21:01,000
+By the way, I believe you understood that you can use any other type besides those that works with
+
+297
+00:21:01,000 --> 00:21:02,000
+files.
+
+298
+00:21:02,000 --> 00:21:07,000
+The way how you will use those types are pretty similar to the way how you use types that work with
+
+299
+00:21:07,000 --> 00:21:08,000
+files.
+
+300
+00:21:08,000 --> 00:21:12,000
+So just feel free to use any implementations of input.
+
+301
+00:21:12,000 --> 00:21:15,000
+Stream output stream reader and writer.
+
+302
+00:21:15,000 --> 00:21:22,000
+Classis example was Bufford writer a similar pay attention that in these matters you can pass a whole
+
+303
+00:21:22,000 --> 00:21:24,000
+string to the method instead of array of bytes.
+
+304
+00:21:25,000 --> 00:21:28,000
+Make sure you understood these examples before moving further.
+
+305
+00:21:28,000 --> 00:21:29,000
+If you.
+
+306
+00:21:29,000 --> 00:21:30,000
+OK, let's proceed.
+
+307
+00:21:31,000 --> 00:21:38,000
+Now, let me show you next examples, these examples about reading from file, the first example shows
+
+308
+00:21:38,000 --> 00:21:41,000
+us how to read from a file with the help of BitStream.
+
+309
+00:21:41,000 --> 00:21:47,000
+As you can see, we create an object of file input stream in Shrivers resources block.
+
+310
+00:21:47,000 --> 00:21:52,000
+Here you can see that I read file by Might's until I would face with minus one.
+
+311
+00:21:52,000 --> 00:21:58,000
+That would mean I reached the end of the file and print Arrison to console.
+
+312
+00:21:58,000 --> 00:22:03,000
+I have to convert integer variable to char but during the reading of files was bitstream.
+
+313
+00:22:04,000 --> 00:22:05,000
+You're going to face one issue.
+
+314
+00:22:06,000 --> 00:22:11,000
+You will be able to read on the first two hundred fifty six characters from Unicode Table.
+
+315
+00:22:11,000 --> 00:22:15,000
+That means you won't be able to read Cyrillic symbols.
+
+316
+00:22:15,000 --> 00:22:20,000
+For example, let me run the program to show you this UNcancel output.
+
+317
+00:22:20,000 --> 00:22:26,000
+You can see that also religious symbols are turned into question marks because it is not possible to
+
+318
+00:22:26,000 --> 00:22:28,000
+represent all symbols of Unicode with one bite.
+
+319
+00:22:29,000 --> 00:22:31,000
+You need two bytes for this.
+
+320
+00:22:31,000 --> 00:22:35,000
+The next example is an example of Barford in between.
+
+321
+00:22:36,000 --> 00:22:42,000
+Here you can see that you can declare multiple resources and add different features to a stream by wrapping
+
+322
+00:22:42,000 --> 00:22:43,000
+it in different objects.
+
+323
+00:22:44,000 --> 00:22:48,000
+For example, data input stream allows you to read specific data type.
+
+324
+00:22:49,000 --> 00:22:55,000
+It declares additional masses like retained, for example, as returns in value and so on.
+
+325
+00:22:56,000 --> 00:23:02,000
+And you can see and understand how to add additional features to existing stream.
+
+326
+00:23:02,000 --> 00:23:05,000
+You have to create some base stream first.
+
+327
+00:23:05,000 --> 00:23:09,000
+And after that, Robert was othertimes in adolescence.
+
+328
+00:23:09,000 --> 00:23:12,000
+Will these architectural patterns in details?
+
+329
+00:23:13,000 --> 00:23:19,000
+I believe you can also understand that you can declare each object in a new line, but also you can
+
+330
+00:23:19,000 --> 00:23:24,000
+get reference only to the last object by calling constructor of different types in one line.
+
+331
+00:23:25,000 --> 00:23:28,000
+Take into account this is Bufford input stream.
+
+332
+00:23:28,000 --> 00:23:32,000
+We can read file not bound by byte, but by lines.
+
+333
+00:23:32,000 --> 00:23:35,000
+That's why Red Line MassArt is available for us here.
+
+334
+00:23:36,000 --> 00:23:41,000
+It is crossed because according to the official documentation, it is deprecated and it is recommended
+
+335
+00:23:41,000 --> 00:23:44,000
+to use characters streams to read files.
+
+336
+00:23:44,000 --> 00:23:46,000
+This is exactly what we have already discussed.
+
+337
+00:23:47,000 --> 00:23:54,000
+And below you can see two maps that show how to read file with characters, streams with buffer reader.
+
+338
+00:23:54,000 --> 00:23:55,000
+You can read file by lines.
+
+339
+00:23:56,000 --> 00:23:59,000
+Please explore these examples by yourself after the lesson.
+
+340
+00:24:00,000 --> 00:24:05,000
+From the syntax standpoint, there is nothing special just using of different types.
+
+341
+00:24:05,000 --> 00:24:10,000
+By the way, in console output you can see that Cyrillic symbols are read properly with the help of
+
+342
+00:24:10,000 --> 00:24:14,000
+characters symbols and there are no more question marks.
+
+343
+00:24:14,000 --> 00:24:20,000
+Now I want to show you how to perform the same operations, but with the help of type from Jowett in
+
+344
+00:24:20,000 --> 00:24:28,000
+your package, you can easily right next to the file with the help of Files Class Just Goldreich MassArt
+
+345
+00:24:28,000 --> 00:24:30,000
+and pass the next arguments.
+
+346
+00:24:30,000 --> 00:24:32,000
+The first argument is a pass object.
+
+347
+00:24:33,000 --> 00:24:40,000
+You already know how to get past object after that pass bytes that you want to write and after that
+
+348
+00:24:40,000 --> 00:24:42,000
+you can optionally pass open options.
+
+349
+00:24:43,000 --> 00:24:45,000
+Let me open the source code of rights, Macit.
+
+350
+00:24:46,000 --> 00:24:51,000
+You can see that there is variable lengths argument of the type open option.
+
+351
+00:24:51,000 --> 00:24:57,000
+That means you can either pass nothing or multiple open options would open option type s.
+
+352
+00:24:58,000 --> 00:24:59,000
+Let me open this interface.
+
+353
+00:25:00,000 --> 00:25:06,000
+This is markhor interface that declares a type that can tell program how to open or create file.
+
+354
+00:25:06,000 --> 00:25:10,000
+I press F for key to see implementations of this type.
+
+355
+00:25:11,000 --> 00:25:14,000
+The most popular in my opinion, is standard open options.
+
+356
+00:25:15,000 --> 00:25:16,000
+Let me open it.
+
+357
+00:25:16,000 --> 00:25:19,000
+This is an informal type that declares main options.
+
+358
+00:25:19,000 --> 00:25:27,000
+How to open access to the file user you want to open, only read the access to the file or also write
+
+359
+00:25:27,000 --> 00:25:27,000
+access.
+
+360
+00:25:27,000 --> 00:25:31,000
+You can specify that you want to add tags to the bottom of the file.
+
+361
+00:25:32,000 --> 00:25:33,000
+By using append option.
+
+362
+00:25:34,000 --> 00:25:37,000
+You can create a file before writing new information there.
+
+363
+00:25:37,000 --> 00:25:41,000
+To do this, we have to pass truncate existant option.
+
+364
+00:25:41,000 --> 00:25:46,000
+If we want to create file, we have to pass create option in case we want to get failer.
+
+365
+00:25:46,000 --> 00:25:50,000
+In case file already exists, we have to use create new option.
+
+366
+00:25:51,000 --> 00:25:55,000
+This is important when you're afraid accidentally overwrite already created file.
+
+367
+00:25:55,000 --> 00:25:58,000
+I believe that delete unclosed is self describing.
+
+368
+00:25:59,000 --> 00:25:59,000
+In my opinion.
+
+369
+00:25:59,000 --> 00:26:02,000
+Those are the main options that we might want to use.
+
+370
+00:26:02,000 --> 00:26:06,000
+You can review documentation for the rest of the options by yourself.
+
+371
+00:26:06,000 --> 00:26:08,000
+Let's get back now to the demo file.
+
+372
+00:26:08,000 --> 00:26:15,000
+And in our practical case, I specify that I want to create file in case it doesn't exist and append
+
+373
+00:26:15,000 --> 00:26:17,000
+tax to the bottom of the file.
+
+374
+00:26:17,000 --> 00:26:18,000
+Is that clear?
+
+375
+00:26:18,000 --> 00:26:19,000
+Great.
+
+376
+00:26:19,000 --> 00:26:23,000
+Also, in case you have a list of things, you can write them to the file.
+
+377
+00:26:23,000 --> 00:26:26,000
+Each string from the list will be written from the new line.
+
+378
+00:26:27,000 --> 00:26:30,000
+Right method is overloaded and you can also specify in.
+
+379
+00:26:31,000 --> 00:26:37,000
+In case you want to write to the file with UTF eight and Cordin just use Constant from Standard Chartered
+
+380
+00:26:37,000 --> 00:26:43,000
+class, the next example shows us how we can read from the file with the help of Joe.
+
+381
+00:26:43,000 --> 00:26:50,000
+In your package, you read file with the help of the stream lines, mistakes pass and optionally you
+
+382
+00:26:50,000 --> 00:26:56,000
+can pass and code and to read from file and when you have stream you can work with it.
+
+383
+00:26:56,000 --> 00:27:01,000
+Likewise, in your regular stream where each string is, each line from the file is as clear.
+
+384
+00:27:02,000 --> 00:27:08,000
+In our particular case, I passed the reference to the masses that can print each line from the new
+
+385
+00:27:08,000 --> 00:27:09,000
+line to console.
+
+386
+00:27:09,000 --> 00:27:12,000
+And here you can see content of the file income.
+
+387
+00:27:12,000 --> 00:27:19,000
+So you can see that the last time when we wrote an array of characters, we overwrite everything that
+
+388
+00:27:19,000 --> 00:27:26,000
+we had that here in command line you can see that we could use lambda function, but I believe you already
+
+389
+00:27:26,000 --> 00:27:28,000
+know how to use functional programming.
+
+390
+00:27:29,000 --> 00:27:32,000
+There is also another way to read content from the file.
+
+391
+00:27:32,000 --> 00:27:35,000
+There is a massive call called Read All Lines.
+
+392
+00:27:35,000 --> 00:27:37,000
+It returns list of strings.
+
+393
+00:27:37,000 --> 00:27:43,000
+The specifics of this method is that all file content will be stored in Java memory.
+
+394
+00:27:43,000 --> 00:27:49,000
+For example, in case you want to process huge files that contains tons of information.
+
+395
+00:27:49,000 --> 00:27:54,000
+Imagine that you want a process to gigabytes of information that contains information about patients
+
+396
+00:27:54,000 --> 00:27:58,000
+from all hospitals around all United States from the last 10 years.
+
+397
+00:27:59,000 --> 00:28:05,000
+And imagine that you have only one gigabyte memory reserved for Heap's base of your Java program.
+
+398
+00:28:05,000 --> 00:28:12,000
+That means you will face with error during programming execution because all text data will be stored
+
+399
+00:28:12,000 --> 00:28:14,000
+in memory of Java program.
+
+400
+00:28:14,000 --> 00:28:20,000
+But you won't face without a memory error in case you would process file stream because it reads file
+
+401
+00:28:20,000 --> 00:28:21,000
+line by line.
+
+402
+00:28:22,000 --> 00:28:28,000
+Always remember that reading and writing operations that can block threat of execution, for example,
+
+403
+00:28:28,000 --> 00:28:30,000
+in this particular case was read.
+
+404
+00:28:30,000 --> 00:28:37,000
+The main threat of execution will be stopped in this line until all file will be read.
+
+405
+00:28:37,000 --> 00:28:40,000
+That's why we're often separate.
+
+406
+00:28:40,000 --> 00:28:44,000
+Threat of execution is used to read or to read information from the file.
+
+407
+00:28:44,000 --> 00:28:46,000
+How to create a separate threat.
+
+408
+00:28:46,000 --> 00:28:51,000
+You are going to learn a little bit later when we'll get this and we'll just read in topic.
+
+409
+00:28:51,000 --> 00:28:54,000
+If you understood this example, let's move on.
+
+410
+00:28:55,000 --> 00:28:56,000
+You're all examples today.
+
+411
+00:28:56,000 --> 00:28:58,000
+You saw that specify in coding.
+
+412
+00:28:58,000 --> 00:29:01,000
+I use special clause that contains a few constants.
+
+413
+00:29:01,000 --> 00:29:03,000
+It is called standard charge sets.
+
+414
+00:29:04,000 --> 00:29:08,000
+Let me open the source code of this class in class outline.
+
+415
+00:29:08,000 --> 00:29:12,000
+You can see that it contains a very limited amount of charge sets.
+
+416
+00:29:12,000 --> 00:29:16,000
+What to do in case you need to specify some custom encoding.
+
+417
+00:29:16,000 --> 00:29:20,000
+You can create object of which are set by the specific charge set name.
+
+418
+00:29:20,000 --> 00:29:24,000
+To do this you can use for name method of charge.
+
+419
+00:29:24,000 --> 00:29:31,000
+That class you have to parse and code name to this method to get exactly charge said that you expect,
+
+420
+00:29:31,000 --> 00:29:37,000
+in case you would like to explore all available charge sets, you can print them to console charge.
+
+421
+00:29:37,000 --> 00:29:43,000
+That class has available charge sets, methods that can return sorted map of jerseyed name mapped to
+
+422
+00:29:43,000 --> 00:29:44,000
+charge that objects.
+
+423
+00:29:45,000 --> 00:29:50,000
+If you understood this, I want to show you a few more interesting matters that will be helpful during
+
+424
+00:29:50,000 --> 00:29:54,000
+your homework and hopefully during your career files.
+
+425
+00:29:54,000 --> 00:30:00,000
+Mercedez has find methods that can help you to find files that match specific condition and you can
+
+426
+00:30:00,000 --> 00:30:02,000
+create a stream out of these files.
+
+427
+00:30:02,000 --> 00:30:06,000
+But to be more specific, you can create a stream for past objects.
+
+428
+00:30:07,000 --> 00:30:13,000
+To do this, you can go find Masset and pass it, pass where you want to start looking from and into
+
+429
+00:30:13,000 --> 00:30:15,000
+value of daps.
+
+430
+00:30:15,000 --> 00:30:20,000
+That is how deep we should go into inner directories while looking for files.
+
+431
+00:30:21,000 --> 00:30:28,000
+And the key argument you have to pass by predicate that will define the logic, what file you are looking
+
+432
+00:30:28,000 --> 00:30:32,000
+for, the byproduct to expose and file attributes.
+
+433
+00:30:32,000 --> 00:30:39,000
+You can see that in this lambda function we use only POS and we want to find all files with Java extension.
+
+434
+00:30:40,000 --> 00:30:43,000
+After that, I use the stream to process all posts.
+
+435
+00:30:44,000 --> 00:30:45,000
+I saw them after that.
+
+436
+00:30:45,000 --> 00:30:50,000
+A turn parser object to string and collect all strings in one line.
+
+437
+00:30:50,000 --> 00:30:57,000
+And in case I found such files and final string is not now and it is not empty, I printed tokens.
+
+438
+00:30:57,000 --> 00:30:59,000
+So can you understand this?
+
+439
+00:30:59,000 --> 00:31:05,000
+You're always welcome to ask questions and Q&A section in case something is still unclear.
+
+440
+00:31:05,000 --> 00:31:12,000
+The results and other helpful Macit you can iterate over all files by calling Walk Masset the different
+
+441
+00:31:12,000 --> 00:31:14,000
+variations of these method.
+
+442
+00:31:14,000 --> 00:31:17,000
+One of them also allows you to set daps during the iteration.
+
+443
+00:31:18,000 --> 00:31:22,000
+This massive returns you stream and you can process it as you wish.
+
+444
+00:31:23,000 --> 00:31:25,000
+That's all what I wanted to share with you today.
+
+445
+00:31:26,000 --> 00:31:28,000
+Let's recap what we have learned today.
+
+446
+00:31:29,000 --> 00:31:31,000
+Today, we learned how to work with files.
+
+447
+00:31:32,000 --> 00:31:36,000
+We also learned how to work with type from jail new package.
+
+448
+00:31:36,000 --> 00:31:41,000
+After that, we learned what bite and character streams are after this lesson.
+
+449
+00:31:41,000 --> 00:31:44,000
+You know how to use thrivers resources block.
+
+450
+00:31:44,000 --> 00:31:50,000
+Now, you know what is a buffer and how to use buffer streams on real examples.
+
+451
+00:31:50,000 --> 00:31:53,000
+You saw how to use and call you in writing and reading.
+
+452
+00:31:53,000 --> 00:31:59,000
+And at the end of the lesson, we learned how to read and write from files with the help of Jouni,
+
+453
+00:31:59,000 --> 00:32:00,000
+your package.
+
+454
+00:32:01,000 --> 00:32:03,000
+Now I want to share with you your homework.
+
+455
+00:32:04,000 --> 00:32:08,000
+I mean, do your homework and attachments, your homework.
+
+456
+00:32:08,000 --> 00:32:12,000
+It is recommended to implement the next task to make sure that you learned this topic.
+
+457
+00:32:13,000 --> 00:32:18,000
+I want you to review the documentation for Java I o package, including file class.
+
+458
+00:32:19,000 --> 00:32:24,000
+Similar to that, I want you to review documentation for Java in your package, including files class
+
+459
+00:32:24,000 --> 00:32:27,000
+that is located in the same package file.
+
+460
+00:32:28,000 --> 00:32:32,000
+Also you have for coding exercises to implement according to the task.
+
+461
+00:32:32,000 --> 00:32:37,000
+Number three, you have to implement MassArt that would read configuration map and would be able to
+
+462
+00:32:37,000 --> 00:32:41,000
+reach an value of the specific property from the config map.
+
+463
+00:32:41,000 --> 00:32:46,000
+And the task number for you would need to iterate over files to calculate the number of files with a
+
+464
+00:32:46,000 --> 00:32:49,000
+specific extension in the exercise.
+
+465
+00:32:49,000 --> 00:32:56,000
+Number five, you have to implement console text editor, user can interact with console to write text
+
+466
+00:32:56,000 --> 00:32:58,000
+to the file and the exercise.
+
+467
+00:32:58,000 --> 00:33:00,000
+Number six is the most interesting in my opinion.
+
+468
+00:33:01,000 --> 00:33:06,000
+As you already understood along, of course, we are going to implement online store application and
+
+469
+00:33:06,000 --> 00:33:13,000
+add additional features to it as we learn new topics in this exercise and of you to add functionality
+
+470
+00:33:13,000 --> 00:33:16,000
+of storing users and products in the file.
+
+471
+00:33:16,000 --> 00:33:23,000
+That will be our first external data storage and one program will be started will read the state from
+
+472
+00:33:23,000 --> 00:33:28,000
+the files that said they are going to have a lot of opportunities to shape your skills.
+
+473
+00:33:29,000 --> 00:33:30,000
+Thanks a lot for your attention.
+
+474
+00:33:30,000 --> 00:33:34,000
+The students hope you found this lesson interesting and useful for you.
+
+475
+00:33:35,000 --> 00:33:36,000
+See you in the next lesson.
+
diff --git a/25 - Input and Output Streams in Java/001 Solution-of-Homework-Online-store-with-data-storage.url b/25 - Input and Output Streams in Java/001 Solution-of-Homework-Online-store-with-data-storage.url
new file mode 100644
index 0000000000000000000000000000000000000000..902da1b1cecf820c50de3e17171898165fb8f610
--- /dev/null
+++ b/25 - Input and Output Streams in Java/001 Solution-of-Homework-Online-store-with-data-storage.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/finaltask/storage
\ No newline at end of file
diff --git a/25 - Input and Output Streams in Java/001 Solution-of-homework.url b/25 - Input and Output Streams in Java/001 Solution-of-homework.url
new file mode 100644
index 0000000000000000000000000000000000000000..efee989fe3acedfbced31ae422d2157010cc7c16
--- /dev/null
+++ b/25 - Input and Output Streams in Java/001 Solution-of-homework.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/io/hw
\ No newline at end of file
diff --git a/25 - Input and Output Streams in Java/001 Source-code-examples-from-lesson.url b/25 - Input and Output Streams in Java/001 Source-code-examples-from-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..a176a7ed620f2b726560b8f0232d6de488fb925d
--- /dev/null
+++ b/25 - Input and Output Streams in Java/001 Source-code-examples-from-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/io
\ No newline at end of file
diff --git a/25 - Input and Output Streams in Java/005 Homework-solution.url b/25 - Input and Output Streams in Java/005 Homework-solution.url
new file mode 100644
index 0000000000000000000000000000000000000000..f914b043685e5c756fd8256893bfb7237e74ab51
--- /dev/null
+++ b/25 - Input and Output Streams in Java/005 Homework-solution.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/finaltask/storage/impl/DefaultUserStoringService.java
\ No newline at end of file
diff --git a/25 - Input and Output Streams in Java/005 Homework.url b/25 - Input and Output Streams in Java/005 Homework.url
new file mode 100644
index 0000000000000000000000000000000000000000..ad1719491a58f97f755bf463046a2f4fbbe381f9
--- /dev/null
+++ b/25 - Input and Output Streams in Java/005 Homework.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://docs.google.com/document/d/1gAwAtOMhaQOCIhc_QM8XreCn_QThfOxAKmw-ufTCk7Y/edit?usp=sharing
\ No newline at end of file
diff --git a/25 - Input and Output Streams in Java/005 Serialization and Cloning_en.srt b/25 - Input and Output Streams in Java/005 Serialization and Cloning_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..9fe06ee99c9d8b7808ca00acacc7675e59142572
--- /dev/null
+++ b/25 - Input and Output Streams in Java/005 Serialization and Cloning_en.srt
@@ -0,0 +1,1096 @@
+1
+00:00:05,000 --> 00:00:11,000
+Hello, there are students in this lesson, we are going to learn what serialisation is and talk about
+
+2
+00:00:11,000 --> 00:00:15,000
+Object Clonan, we'll start from understanding why do we need signalization?
+
+3
+00:00:15,000 --> 00:00:21,000
+I will explain you what the serializable interface for after that unreal example.
+
+4
+00:00:21,000 --> 00:00:22,000
+We'll try to serialize.
+
+5
+00:00:22,000 --> 00:00:27,000
+And the last few objects also will learn Externalisation.
+
+6
+00:00:27,000 --> 00:00:33,000
+Today you're going to find what the difference between serializable and externalising is.
+
+7
+00:00:33,000 --> 00:00:39,000
+Once you learn that, we'll talk about object and we'll review what is deep and shallow.
+
+8
+00:00:39,000 --> 00:00:44,000
+Clonan, I'll tell you how to override clone method to support Deep Clonan.
+
+9
+00:00:44,000 --> 00:00:47,000
+In this lesson, you're going to see a lot of examples.
+
+10
+00:00:48,000 --> 00:00:49,000
+So let's start.
+
+11
+00:00:50,000 --> 00:00:53,000
+First of all, let me give the answer and question.
+
+12
+00:00:53,000 --> 00:00:55,000
+What serialisation is serialisation?
+
+13
+00:00:55,000 --> 00:00:59,000
+Is a process of converting objects to a stream of bytes.
+
+14
+00:00:59,000 --> 00:01:03,000
+Decimalization is a process of converting stream of bytes to an object.
+
+15
+00:01:04,000 --> 00:01:08,000
+In simple words, you can represent your Java object in sequence of bytes.
+
+16
+00:01:09,000 --> 00:01:15,000
+After that, you can either store it on local computer or centralized object over Internet.
+
+17
+00:01:15,000 --> 00:01:16,000
+It's up to you.
+
+18
+00:01:16,000 --> 00:01:19,000
+In case you understood what serialization is.
+
+19
+00:01:19,000 --> 00:01:23,000
+Let's understand the problem and why we might want to use terrorization.
+
+20
+00:01:24,000 --> 00:01:28,000
+To help you understand this, I'm going to discuss with you a few real life cases.
+
+21
+00:01:28,000 --> 00:01:35,000
+Imagine that you have to service that are in the same code and you need pass information from one machine
+
+22
+00:01:35,000 --> 00:01:36,000
+to another.
+
+23
+00:01:36,000 --> 00:01:43,000
+You can create an object and serialize it and pass a sequence of bytes over the network to another server.
+
+24
+00:01:44,000 --> 00:01:50,000
+The second server will decentralize your message and construct a new object out of the bytes that we
+
+25
+00:01:50,000 --> 00:01:51,000
+have sent.
+
+26
+00:01:51,000 --> 00:01:55,000
+That's how you can pass information from one server to another.
+
+27
+00:01:56,000 --> 00:01:57,000
+Another example.
+
+28
+00:01:57,000 --> 00:02:00,000
+It's when you need to store some data on the local computer.
+
+29
+00:02:00,000 --> 00:02:06,000
+Imagine that you have a game or another desktop application, for example, your diary.
+
+30
+00:02:06,000 --> 00:02:13,000
+And when the user close the program you want to say is a state of the program, it could be game progress,
+
+31
+00:02:13,000 --> 00:02:15,000
+a list of users plans.
+
+32
+00:02:15,000 --> 00:02:16,000
+It doesn't matter.
+
+33
+00:02:16,000 --> 00:02:20,000
+And you can serialize objects that contains this information.
+
+34
+00:02:20,000 --> 00:02:23,000
+One program is closed and decentralized.
+
+35
+00:02:23,000 --> 00:02:24,000
+That one program has started again.
+
+36
+00:02:25,000 --> 00:02:26,000
+It is pretty convenient, don't you think?
+
+37
+00:02:26,000 --> 00:02:33,000
+So one more practical need for serialization is to make an exact copy of an object.
+
+38
+00:02:33,000 --> 00:02:39,000
+Today we'll talk about this and you learn how to clone object with the help of civilization mechanism.
+
+39
+00:02:40,000 --> 00:02:43,000
+How else you can use a translation mechanism.
+
+40
+00:02:43,000 --> 00:02:48,000
+Imagine that you have really huge objects that takes ten minutes to construct.
+
+41
+00:02:48,000 --> 00:02:54,000
+Just imagine that it is better for you to cache this object because this resolution of this object will
+
+42
+00:02:54,000 --> 00:02:56,000
+take up to ten seconds, for example.
+
+43
+00:02:56,000 --> 00:03:00,000
+So sometimes you may want to cacio objects.
+
+44
+00:03:01,000 --> 00:03:04,000
+These are just a few examples when you might want to use serialisation.
+
+45
+00:03:05,000 --> 00:03:06,000
+Interesting if.
+
+46
+00:03:06,000 --> 00:03:11,000
+Yes, let's run how the resolution works for this lesson.
+
+47
+00:03:11,000 --> 00:03:13,000
+I prepared examples that I'm going to share with you today.
+
+48
+00:03:14,000 --> 00:03:15,000
+Let's jump to Eclipse.
+
+49
+00:03:16,000 --> 00:03:23,000
+Imagine that we have class employee that is some class from our application and this class has next
+
+50
+00:03:23,000 --> 00:03:27,000
+properties, idea, name and list of properties of map type.
+
+51
+00:03:28,000 --> 00:03:34,000
+This class also has getters and setters and imagines that at some point in our program we want to serialize
+
+52
+00:03:34,000 --> 00:03:35,000
+this object.
+
+53
+00:03:35,000 --> 00:03:41,000
+The first thing we have to do is to mark specific type with serializable interface.
+
+54
+00:03:41,000 --> 00:03:47,000
+This is important because without implementing this interface, you will get an exception during the
+
+55
+00:03:47,000 --> 00:03:51,000
+serialization to be more specific, not serializable exception.
+
+56
+00:03:51,000 --> 00:03:57,000
+Let's review the source code of this interface and you can see that this interface declares no mascot's.
+
+57
+00:03:58,000 --> 00:04:00,000
+This is a marker interface.
+
+58
+00:04:00,000 --> 00:04:07,000
+It is a rule in Java that enables the ability of a class it should implements this interface.
+
+59
+00:04:07,000 --> 00:04:10,000
+OK, now let's get back to our file.
+
+60
+00:04:11,000 --> 00:04:14,000
+Now we have employee time that is ready to be centralized.
+
+61
+00:04:15,000 --> 00:04:16,000
+Let's open our demo file.
+
+62
+00:04:17,000 --> 00:04:19,000
+I create object of type employee.
+
+63
+00:04:19,000 --> 00:04:23,000
+I satija name and map with properties.
+
+64
+00:04:23,000 --> 00:04:27,000
+Our A map includes salary and the city great.
+
+65
+00:04:27,000 --> 00:04:29,000
+The Serialize object.
+
+66
+00:04:29,000 --> 00:04:35,000
+I created a separate matter that is called centralized simply lets you use a source code of that massive.
+
+67
+00:04:35,000 --> 00:04:38,000
+I want to declare object outputs three type.
+
+68
+00:04:38,000 --> 00:04:41,000
+It can be created on the basis of output stream.
+
+69
+00:04:42,000 --> 00:04:48,000
+So I create object output stream and POS but array output stream into it.
+
+70
+00:04:48,000 --> 00:04:56,000
+Pay attention here instead of battery output stream, you can specify any other type that extends output
+
+71
+00:04:56,000 --> 00:04:56,000
+stream.
+
+72
+00:04:57,000 --> 00:05:04,000
+I declare all streams in Try with their sources blog inside the blog, I called MassArt right object
+
+73
+00:05:04,000 --> 00:05:12,000
+and pass the reference to my employee object that from this Massett I return by the output stream because
+
+74
+00:05:12,000 --> 00:05:14,000
+I want to source in reference to this object.
+
+75
+00:05:15,000 --> 00:05:21,000
+When times come, I will use this battery output stream object to decentralize my employee object.
+
+76
+00:05:21,000 --> 00:05:22,000
+That's it.
+
+77
+00:05:22,000 --> 00:05:27,000
+I have just generalized and play object how I can decentralize it.
+
+78
+00:05:28,000 --> 00:05:31,000
+Let's review the source code of another method decentralized.
+
+79
+00:05:31,000 --> 00:05:38,000
+Simply, I posta this massive battery output stream that is a stream where my employee object was written
+
+80
+00:05:38,000 --> 00:05:40,000
+as a sequence of bytes.
+
+81
+00:05:40,000 --> 00:05:47,000
+In this method I create object input stream and pass to it by three input stream object that is created
+
+82
+00:05:47,000 --> 00:05:50,000
+on the basis of my battery output stream.
+
+83
+00:05:51,000 --> 00:05:58,000
+In simple words, I redirected my output stream to input stream and now I want to read it.
+
+84
+00:05:59,000 --> 00:06:02,000
+Other sources are declared in other sources.
+
+85
+00:06:02,000 --> 00:06:03,000
+Block one.
+
+86
+00:06:03,000 --> 00:06:06,000
+All objects are created equal object.
+
+87
+00:06:06,000 --> 00:06:11,000
+Masset pay attention that this mass returns object of type object.
+
+88
+00:06:12,000 --> 00:06:19,000
+In case you want to have specific type, you have to cost this object to your time and I return employee
+
+89
+00:06:19,000 --> 00:06:22,000
+object from this massive in our main Macit.
+
+90
+00:06:22,000 --> 00:06:26,000
+I want to bring the employee that we got after the serialization.
+
+91
+00:06:27,000 --> 00:06:30,000
+Let me run the program to show you and transload.
+
+92
+00:06:31,000 --> 00:06:37,000
+My program created an object after that, the program centralized template and after that the program
+
+93
+00:06:37,000 --> 00:06:44,000
+decentralized it and printed object to console and you can see that it is an absolute copy of our original
+
+94
+00:06:44,000 --> 00:06:45,000
+employee.
+
+95
+00:06:45,000 --> 00:06:49,000
+Can you understand now what centralization and decentralization is?
+
+96
+00:06:49,000 --> 00:06:50,000
+Great.
+
+97
+00:06:50,000 --> 00:06:54,000
+Let me add a few more details to serialisation and this realization.
+
+98
+00:06:54,000 --> 00:06:56,000
+Let's go one by one.
+
+99
+00:06:56,000 --> 00:07:02,000
+First of all, you saw that my employee class has specific properties, serial version Yagi.
+
+100
+00:07:02,000 --> 00:07:10,000
+What does this variable for serial version UIGEA is a constant that uniquely in the device, a version
+
+101
+00:07:10,000 --> 00:07:14,000
+of a serializable class universalization process.
+
+102
+00:07:14,000 --> 00:07:18,000
+Java virtual machine verifies this constant why?
+
+103
+00:07:18,000 --> 00:07:26,000
+Imagine that we have original version of an employee class visualized the object and on the other machine
+
+104
+00:07:26,000 --> 00:07:29,000
+where our program is running or even on our machine.
+
+105
+00:07:29,000 --> 00:07:35,000
+But after user updated version of our application, imagine that there is an updated version of employee
+
+106
+00:07:35,000 --> 00:07:42,000
+class, for example, instead of the map with properties, we have separate properties for salary and
+
+107
+00:07:42,000 --> 00:07:45,000
+C.G. and there is no more property of type map anymore.
+
+108
+00:07:45,000 --> 00:07:52,000
+That means that error will happen during institutionalization and our sequence of byte won't be able
+
+109
+00:07:52,000 --> 00:07:59,000
+to be mapped against the current employee type and to distinguish versions of classes that are serialized.
+
+110
+00:07:59,000 --> 00:08:04,000
+This constant exists sometimes, developer said default serial version.
+
+111
+00:08:04,000 --> 00:08:10,000
+Yazji This is equal to one and that's it known that the serial version is optional.
+
+112
+00:08:11,000 --> 00:08:15,000
+You can just ignore this eclipse will show you a warning, but nothing about that.
+
+113
+00:08:16,000 --> 00:08:19,000
+Let's talk about what a transient keyword is.
+
+114
+00:08:19,000 --> 00:08:21,000
+It is better to understand this.
+
+115
+00:08:21,000 --> 00:08:21,000
+An example.
+
+116
+00:08:22,000 --> 00:08:28,000
+Let me add a transient keyword in the property and now let me run my program one more time.
+
+117
+00:08:28,000 --> 00:08:30,000
+Look at the console output.
+
+118
+00:08:30,000 --> 00:08:33,000
+Can its users name property is now.
+
+119
+00:08:33,000 --> 00:08:34,000
+Why?
+
+120
+00:08:34,000 --> 00:08:39,000
+Because Transend keyword tells to ignore this property during the serialization.
+
+121
+00:08:39,000 --> 00:08:43,000
+The string value of name is just not stored to the output stream.
+
+122
+00:08:44,000 --> 00:08:46,000
+Let's get back to inplay class.
+
+123
+00:08:46,000 --> 00:08:48,000
+I will remove transient keywords.
+
+124
+00:08:49,000 --> 00:08:52,000
+I want you to pay attention to two matters here, right?
+
+125
+00:08:52,000 --> 00:08:54,000
+Object and object.
+
+126
+00:08:54,000 --> 00:09:01,000
+Especially pay attention to the access modifiers, return type of data and potential exceptions that
+
+127
+00:09:01,000 --> 00:09:01,000
+can be thrown.
+
+128
+00:09:02,000 --> 00:09:07,000
+This is just a convention and this is something what we have just to remember, in case you want to
+
+129
+00:09:07,000 --> 00:09:13,000
+customize your object before serialization or after decimalization, you can declare these methods in
+
+130
+00:09:13,000 --> 00:09:16,000
+your type and perform anything you need.
+
+131
+00:09:16,000 --> 00:09:22,000
+For example, I have can so random text just to prove you that these methods are invoked.
+
+132
+00:09:23,000 --> 00:09:29,000
+You can always use default, write, object and default to object to process your serialization further.
+
+133
+00:09:29,000 --> 00:09:33,000
+In this methods, you can handle initialization of transient fields.
+
+134
+00:09:33,000 --> 00:09:36,000
+For example, Hobbs's makes things clearer.
+
+135
+00:09:36,000 --> 00:09:38,000
+Let's move on now.
+
+136
+00:09:38,000 --> 00:09:44,000
+Imagine the case that you want to serialize object and you want explicitly tell that process of civilization
+
+137
+00:09:44,000 --> 00:09:45,000
+should be customized.
+
+138
+00:09:46,000 --> 00:09:52,000
+For example, each user has a password or any other sensitive information and you want to encrypt this
+
+139
+00:09:52,000 --> 00:09:56,000
+information before serialization and decrypt after serialization.
+
+140
+00:09:57,000 --> 00:10:04,000
+For the sake of them, I create one more type called user attention, it implements externalizes.
+
+141
+00:10:04,000 --> 00:10:10,000
+All this time has only two fields, Zaya nickname and password.
+
+142
+00:10:11,000 --> 00:10:14,000
+You can see two constructors, getters and setters.
+
+143
+00:10:14,000 --> 00:10:20,000
+And the most interesting part in case you implement externalise all you have to implement, right?
+
+144
+00:10:20,000 --> 00:10:22,000
+External and with external mascot's.
+
+145
+00:10:23,000 --> 00:10:28,000
+It is similar to the way we view it with the serializable type employee and private marcedes.
+
+146
+00:10:29,000 --> 00:10:35,000
+This is more object oriented way to say that this type contains custom logic for serialisation and decentralization.
+
+147
+00:10:36,000 --> 00:10:37,000
+We would open this interface.
+
+148
+00:10:37,000 --> 00:10:44,000
+We would notice that it extends serializable in this messenger as a serialisation and right to the output
+
+149
+00:10:44,000 --> 00:10:46,000
+nickname and custom passwords.
+
+150
+00:10:47,000 --> 00:10:49,000
+We can encode password here, for example.
+
+151
+00:10:50,000 --> 00:10:54,000
+And in the read External Masset, I should read properties one by one.
+
+152
+00:10:54,000 --> 00:10:57,000
+You have to read properties in the same sequence.
+
+153
+00:10:57,000 --> 00:11:02,000
+We wrote them here and you can see that I initialize state of the current object.
+
+154
+00:11:03,000 --> 00:11:09,000
+Let me open our demo program to test utilization and decentralization and create user object first.
+
+155
+00:11:10,000 --> 00:11:16,000
+And after that I call similar methods that we saw during the serialization example that tensions that
+
+156
+00:11:16,000 --> 00:11:18,000
+I created user with this specific password.
+
+157
+00:11:19,000 --> 00:11:25,000
+Let me run the program now in console output, you can see that password is different.
+
+158
+00:11:25,000 --> 00:11:30,000
+That is because we implemented custom logic of civilization and serialization.
+
+159
+00:11:30,000 --> 00:11:31,000
+Does it make sense?
+
+160
+00:11:32,000 --> 00:11:33,000
+Awesome.
+
+161
+00:11:34,000 --> 00:11:38,000
+Now, when you completely learn serialisation, let me talk about a different topic.
+
+162
+00:11:38,000 --> 00:11:40,000
+Let's discuss cloning now.
+
+163
+00:11:41,000 --> 00:11:45,000
+Sometimes in a program you might want to create exact copy of the same object.
+
+164
+00:11:45,000 --> 00:11:52,000
+For example, you want to do some modifications in user object, but you also need to store that reference
+
+165
+00:11:52,000 --> 00:11:53,000
+to the original object.
+
+166
+00:11:53,000 --> 00:12:00,000
+That is helpful in some specific cases when you need to keep both data objects original and updated
+
+167
+00:12:00,000 --> 00:12:04,000
+one and pass them to the front end to compare them together.
+
+168
+00:12:05,000 --> 00:12:08,000
+Each Java object has access to clone masses.
+
+169
+00:12:08,000 --> 00:12:11,000
+Let me open the source code of object class.
+
+170
+00:12:11,000 --> 00:12:13,000
+You can find clone method here.
+
+171
+00:12:14,000 --> 00:12:20,000
+As you can see, this is a native Macit and we can explore its original source code right now.
+
+172
+00:12:20,000 --> 00:12:24,000
+But what we can see is that the massive has protected access modifier.
+
+173
+00:12:25,000 --> 00:12:26,000
+What does it mean?
+
+174
+00:12:26,000 --> 00:12:33,000
+That mean we can't call clone Masset on each object by default, but we have access to this.
+
+175
+00:12:33,000 --> 00:12:35,000
+Protect MassArt inside the class.
+
+176
+00:12:36,000 --> 00:12:37,000
+Let me show you this.
+
+177
+00:12:37,000 --> 00:12:41,000
+All examples that are related to cloning will be stored in cloning package.
+
+178
+00:12:42,000 --> 00:12:45,000
+Let me open this cloning demo file here.
+
+179
+00:12:45,000 --> 00:12:48,000
+You can see that I created the object of a user type.
+
+180
+00:12:48,000 --> 00:12:53,000
+And when I call clone MassArt on this object, I get a completion error.
+
+181
+00:12:53,000 --> 00:13:00,000
+That is because Clone Massett has a protected access modifier and available inside the user type in
+
+182
+00:13:00,000 --> 00:13:01,000
+this class.
+
+183
+00:13:01,000 --> 00:13:07,000
+Java compiler just can see it to make it available outside of the class.
+
+184
+00:13:07,000 --> 00:13:14,000
+We have to override this method inside the type and increase the visibility by changing the access modifier
+
+185
+00:13:14,000 --> 00:13:16,000
+from protected to public.
+
+186
+00:13:17,000 --> 00:13:19,000
+For example, here is an all the time.
+
+187
+00:13:19,000 --> 00:13:24,000
+It contains fields, constructors, getters and setters and clone MassArt.
+
+188
+00:13:24,000 --> 00:13:30,000
+Here you can see that I override clone Masset and make it public inside the method.
+
+189
+00:13:30,000 --> 00:13:36,000
+I just invoke original clone method from the object class you Mycenae that I implemented clone MassArt.
+
+190
+00:13:36,000 --> 00:13:40,000
+Let's check how it works inside the main message.
+
+191
+00:13:40,000 --> 00:13:41,000
+I create a list of products first.
+
+192
+00:13:42,000 --> 00:13:44,000
+Now I can create an object of all the time.
+
+193
+00:13:45,000 --> 00:13:52,000
+I pass some random creditcard no list of products that are associated with this or the end user i.e.
+
+194
+00:13:52,000 --> 00:13:55,000
+who made this so that this is my original order.
+
+195
+00:13:55,000 --> 00:13:58,000
+I printed the console in the next line.
+
+196
+00:13:58,000 --> 00:14:02,000
+I want to clone my original or the object pad tensions.
+
+197
+00:14:02,000 --> 00:14:10,000
+That clone MassArt maestro clone not supported exception when one type that is cloned doesn't implement
+
+198
+00:14:10,000 --> 00:14:12,000
+Coonamble interface.
+
+199
+00:14:12,000 --> 00:14:15,000
+Let me open the source code of all the type one more time.
+
+200
+00:14:16,000 --> 00:14:20,000
+You can see that my order type implements cleanable interface.
+
+201
+00:14:20,000 --> 00:14:21,000
+Let's open this interface.
+
+202
+00:14:22,000 --> 00:14:29,000
+You can see that this is also an interface and Java verifies during the clone and sometimes it is going
+
+203
+00:14:29,000 --> 00:14:29,000
+to be cloned.
+
+204
+00:14:30,000 --> 00:14:32,000
+Implements Cleanable interface.
+
+205
+00:14:33,000 --> 00:14:40,000
+Take this as a permission to all object of this type to be cloned and in case this interface is implemented
+
+206
+00:14:40,000 --> 00:14:45,000
+in the time Java believes you that this permission has been granted, is that clear?
+
+207
+00:14:46,000 --> 00:14:47,000
+Awesome.
+
+208
+00:14:47,000 --> 00:14:49,000
+Let's get back to our demo file.
+
+209
+00:14:49,000 --> 00:14:52,000
+When I cloned object, I printed tokens.
+
+210
+00:14:52,000 --> 00:14:56,000
+So let's run this program in console output.
+
+211
+00:14:56,000 --> 00:15:01,000
+We can compare these two orders, but believe me, they are the same.
+
+212
+00:15:01,000 --> 00:15:03,000
+But they're interesting things to come.
+
+213
+00:15:04,000 --> 00:15:11,000
+What if in the cloned object I will modify state, for example, I will clear all products from the
+
+214
+00:15:11,000 --> 00:15:16,000
+cloned order and get all products and Cochlear Massud on the list.
+
+215
+00:15:17,000 --> 00:15:23,000
+After that I print original order and you can see that list of products is also clean here.
+
+216
+00:15:24,000 --> 00:15:25,000
+How that can be.
+
+217
+00:15:26,000 --> 00:15:31,000
+This may seem to be a weird thing, but this is the way how clone Masset works by default.
+
+218
+00:15:31,000 --> 00:15:38,000
+This is called Shallow Clonan, you shallow clonan only references are copied.
+
+219
+00:15:38,000 --> 00:15:44,000
+Shallow clone in the works just fine for primitive types because they are already stores the value in
+
+220
+00:15:44,000 --> 00:15:53,000
+themselves with reference types of data only references are cloned during shallow cloning, but objects
+
+221
+00:15:53,000 --> 00:15:56,000
+that stand behind those references are not cloned.
+
+222
+00:15:57,000 --> 00:16:04,000
+Geep cloning is focused on the cloning of the whole object's graph, including properties of reference
+
+223
+00:16:04,000 --> 00:16:08,000
+types inside the object and properties of reference types inside those objects.
+
+224
+00:16:09,000 --> 00:16:10,000
+Can you understand this?
+
+225
+00:16:11,000 --> 00:16:11,000
+Awesome.
+
+226
+00:16:12,000 --> 00:16:17,000
+So what we have to do, we have to override clone Masset to make it also clone objects.
+
+227
+00:16:17,000 --> 00:16:19,000
+That stands behind the references.
+
+228
+00:16:20,000 --> 00:16:25,000
+For the sake of the Dharma, I created one more order type that supports the cloning.
+
+229
+00:16:25,000 --> 00:16:28,000
+Let's open the step and explore its clone method.
+
+230
+00:16:28,000 --> 00:16:33,000
+At the beginning, I called the whole object and after that I put all.
+
+231
+00:16:33,000 --> 00:16:39,000
+Only on mutable objects in this particular time, I have only one mutable property.
+
+232
+00:16:39,000 --> 00:16:41,000
+This is a list of products.
+
+233
+00:16:41,000 --> 00:16:43,000
+Spring type is immutable.
+
+234
+00:16:43,000 --> 00:16:46,000
+It will be impossible to change its state after creation.
+
+235
+00:16:46,000 --> 00:16:49,000
+It will be possible only to Saturnus three.
+
+236
+00:16:49,000 --> 00:16:53,000
+That's why I am not worrying about it also.
+
+237
+00:16:53,000 --> 00:16:56,000
+And don't worry about in the field since this is a primitive time.
+
+238
+00:16:56,000 --> 00:17:02,000
+But for products list, I did a copy and I said this copy to my client object.
+
+239
+00:17:02,000 --> 00:17:06,000
+Now let's check how deep coding works for this type.
+
+240
+00:17:07,000 --> 00:17:11,000
+I initialize product list that was cleared one more time after that.
+
+241
+00:17:11,000 --> 00:17:14,000
+A great object of our new type zann.
+
+242
+00:17:14,000 --> 00:17:21,000
+I clone this object and similar to the previous example, actually as a list of products in my client
+
+243
+00:17:21,000 --> 00:17:28,000
+object and print two objects to consult, I expect that products placed in original order won't be empty.
+
+244
+00:17:29,000 --> 00:17:35,000
+In Arkansas, we can see that we achieved our goal and product list is not empty in my original order
+
+245
+00:17:35,000 --> 00:17:37,000
+and it is empty in cloned order.
+
+246
+00:17:38,000 --> 00:17:38,000
+Great.
+
+247
+00:17:39,000 --> 00:17:41,000
+Now you know how to do Geep Clonan.
+
+248
+00:17:41,000 --> 00:17:44,000
+Feel free to let me know in case you have any questions.
+
+249
+00:17:45,000 --> 00:17:47,000
+None how serialization works.
+
+250
+00:17:47,000 --> 00:17:53,000
+You might think that serialize and visualize an object doesn't sound like a better year in case you
+
+251
+00:17:53,000 --> 00:18:00,000
+want to clone an object because implement clone MassArt that would properly clone old graph of objects.
+
+252
+00:18:00,000 --> 00:18:02,000
+It can be very complicated task.
+
+253
+00:18:02,000 --> 00:18:07,000
+Sometimes you may consider serialisation mechanism to make a clone very fast.
+
+254
+00:18:08,000 --> 00:18:10,000
+That's all what I wanted to share with you today.
+
+255
+00:18:10,000 --> 00:18:12,000
+Let's recap what we have learned today.
+
+256
+00:18:13,000 --> 00:18:19,000
+In this lesson we learned what serialization is rereviewed serializable Marka interface.
+
+257
+00:18:19,000 --> 00:18:23,000
+Now you know how centralized and decentralized your objects.
+
+258
+00:18:23,000 --> 00:18:27,000
+You also learned what externalise interface is.
+
+259
+00:18:27,000 --> 00:18:30,000
+After that, we learned how Clonan Java works.
+
+260
+00:18:31,000 --> 00:18:33,000
+Now, you know, cleanable interface.
+
+261
+00:18:33,000 --> 00:18:37,000
+Today we learned what is the difference between deep and shallow clonan.
+
+262
+00:18:37,000 --> 00:18:41,000
+Also, we had a lot of practice that will help you to complete your homework.
+
+263
+00:18:42,000 --> 00:18:43,000
+Let's review your homework now.
+
+264
+00:18:44,000 --> 00:18:48,000
+After this topic, you are going to have only one simple coding exercise.
+
+265
+00:18:48,000 --> 00:18:54,000
+I promise you, we keep improving our online shop, taking into account all the time, has a list of
+
+266
+00:18:54,000 --> 00:18:55,000
+products inside.
+
+267
+00:18:55,000 --> 00:18:59,000
+It will be not very convenient to store it in comma separated files.
+
+268
+00:18:59,000 --> 00:19:06,000
+In scope of this task, you have to serialize all orders to the file and one program will be started
+
+269
+00:19:06,000 --> 00:19:06,000
+again.
+
+270
+00:19:06,000 --> 00:19:10,000
+You have to decentralize or this again home.
+
+271
+00:19:10,000 --> 00:19:11,000
+This is clear.
+
+272
+00:19:11,000 --> 00:19:13,000
+That's all what I wanted to share with you today.
+
+273
+00:19:14,000 --> 00:19:15,000
+Thanks a lot for your attention.
+
+274
+00:19:15,000 --> 00:19:18,000
+Have a great day here in the next lesson.
+
diff --git a/25 - Input and Output Streams in Java/005 Source-code-examples-from-the-lesson-Cloning.url b/25 - Input and Output Streams in Java/005 Source-code-examples-from-the-lesson-Cloning.url
new file mode 100644
index 0000000000000000000000000000000000000000..8476c1104b2c9ccb536ad300b657662bbbc8a929
--- /dev/null
+++ b/25 - Input and Output Streams in Java/005 Source-code-examples-from-the-lesson-Cloning.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/cloning
\ No newline at end of file
diff --git a/25 - Input and Output Streams in Java/005 Source-code-examples-from-the-lesson-Serialization.url b/25 - Input and Output Streams in Java/005 Source-code-examples-from-the-lesson-Serialization.url
new file mode 100644
index 0000000000000000000000000000000000000000..ed76035206624525c201ff3f659baab2423a88fa
--- /dev/null
+++ b/25 - Input and Output Streams in Java/005 Source-code-examples-from-the-lesson-Serialization.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/io/serialization
\ No newline at end of file
diff --git a/25 - Input and Output Streams in Java/006 Quiz InputOutput Streams - Check yourself.html b/25 - Input and Output Streams in Java/006 Quiz InputOutput Streams - Check yourself.html
new file mode 100644
index 0000000000000000000000000000000000000000..3284d20b867a1d29cda40d331a2bd8134a9d32d0
--- /dev/null
+++ b/25 - Input and Output Streams in Java/006 Quiz InputOutput Streams - Check yourself.html
@@ -0,0 +1,69 @@
+
+
+
+
+
+ Quiz InputOutput Streams - Check yourself
+
+
+
+
+
+
+
Quiz InputOutput Streams - Check yourself
+
Quiz Link: https://forms.gle/jpwGZB1p7raYHuZ69
The quiz doesn’t require you to log in or submit any personal information. Your data privacy is my priority.
The Quiz covers content from the following lessons:
Quiz Instructions:
This quiz is designed to help you check your understanding of the content from the previous lessons. All questions are based only on material covered in the lessons you've already watched, so there’s no need to worry about unfamiliar topics.
Each question has one correct answer. Select the best answer and click "Submit" when you're ready.
After submitting, you'll see your score. For each question, you earn 1 point.
Click "View Results" to see the explanations for each correct answer. Reviewing these explanations can help reinforce your understanding.
If you score below 70%, I recommend revisiting the previous lessons. However, if the explanations make sense and you’re confident in your understanding, feel free to move on.
If any explanations are unclear, please don’t hesitate to post questions in the Q&A section—I’m here to help!
+
+
+
+
diff --git a/25 - Input and Output Streams in Java/external-links.txt b/25 - Input and Output Streams in Java/external-links.txt
new file mode 100644
index 0000000000000000000000000000000000000000..847b30c364ef23775edc0034fde71bdc09a75a01
--- /dev/null
+++ b/25 - Input and Output Streams in Java/external-links.txt
@@ -0,0 +1,24 @@
+
+001 Source-code-examples-from-lesson
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/io
+
+001 Homework
+https://docs.google.com/document/d/12mpGjQti9SwYrCS-0RU-WNYtEQCKSFwjgiCS8iKDnTw/edit?usp=sharing
+
+001 Solution-of-homework
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/io/hw
+
+001 Solution-of-Homework-Online-store-with-data-storage
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/finaltask/storage
+
+005 Source-code-examples-from-the-lesson-Serialization
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/io/serialization
+
+005 Source-code-examples-from-the-lesson-Cloning
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/cloning
+
+005 Homework
+https://docs.google.com/document/d/1gAwAtOMhaQOCIhc_QM8XreCn_QThfOxAKmw-ufTCk7Y/edit?usp=sharing
+
+005 Homework-solution
+https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/finaltask/storage/impl/DefaultUserStoringService.java
diff --git a/26 - ===== IO in Java Interview Preparation =====/001 Part 1 Java IO Interview - Questions and Answers.html b/26 - ===== IO in Java Interview Preparation =====/001 Part 1 Java IO Interview - Questions and Answers.html
new file mode 100644
index 0000000000000000000000000000000000000000..ce8e8e48d6dc2fce2e2aadc784f33456e051bbfd
--- /dev/null
+++ b/26 - ===== IO in Java Interview Preparation =====/001 Part 1 Java IO Interview - Questions and Answers.html
@@ -0,0 +1,69 @@
+
+
+
+
+
+ Part 1 Java IO Interview - Questions and Answers
+
+
+
+
+
+
+
Part 1 Java IO Interview - Questions and Answers
+
I/O streams are used to transfer data to file streams, to the console, or to network connections. There are two kinds of I/O streams: byte and character.
I / O (input / output, input-output) - the interaction between the information processor and its provider and / or recipient. Input is the signal or data received by the handler, and output is the signal or data sent by (or from) it.
NIO (/*in the context of Java*/ Non-blocking I/O, New I/O) is a collection of application programming interfaces for the Java language designed to implement high-performance I/O operations.
Key features of NIO:
Channels and Selectors: NIO supports various types of channels. A pipe is an abstraction of lower-level file system objects (such as memory-mapped files and file locks) that allow data to be transferred at a faster rate. Channels are non-blocking, and therefore Java provides other tools such as a selector, which allows you to choose a ready channel for data transfer, and a socket, which is a tool for blocking.
Buffers: Java 7 introduced buffering for all primitive wrapper classes (except Boolean). An abstract Buffer class has appeared, which provides operations such as clear, flip, mark, etc. Its subclasses provide methods for getting and setting data.
Encodings: Java 7 introduced encodings (java.nio.charset), encoders and decoders for displaying Unicode bytes and characters.
Byte streams: java.io.InputStream, java.io.OutputStream;
Character streams: java.io.Reader, java.io.Writer;
The OutputStream class is an abstract class that defines streaming byte output. This category contains classes that define whether your data is going into a byte array (but not directly to a String; you are supposed to be able to create it from a byte array), to a file, or to a pipe.
The base class InputStream represents classes that receive data from various sources:
byte array
string
file
channel (pipe): data is placed at one end and retrieved from the other
a sequence of different streams that can be combined into a single stream
other sources (for example, internet connection)
Character streams have two main abstract classes, Reader and Writer, that manage streams of Unicode characters. The Reader class is an abstract class that defines character stream input. The Writer class is an abstract class that defines character stream output. In case of errors, all methods of the class throw an IOException.
Popular Subclasses of the base InputStream class:
StringBufferInputStream - turns a string (String) into an InputStream.
SequenceInputStream - merges two or more InputStreams into a single stream.
PushbackInputStream - an input stream that supports a one-byte return to the input stream.
PipedInputStream - implements the concept of an input channel.
ObjectInputStream - input stream for objects.
InputStream is an abstract class that describes an input stream.
FilterInputStream is an abstract class that provides an interface for add-on classes that add useful properties to existing streams.
FileInputStream - for reading information from a file.
DataInputStream - An input stream that includes methods for reading standard Java data types.
ByteArrayInputStream - allows you to use an in-memory buffer (byte array) as the data source for the input stream.
BufferedInputStream - buffered input stream.
RandomAccessFile is a class that inherits directly from Object and does not inherit from the I/O base classes above. Designed to work with files, supporting random access to their contents.
Working with the RandomAccessFile class is similar to using the DataInputStream and DataOutputStream streams combined in the same class (they implement the same DataInput and DataOutput interfaces). In addition, the seek() method allows you to move to a specific position and change the value stored there.
When using RandomAccessFile, you need to know the structure of the file. The RandomAccessFile class contains methods for reading and writing UTF-8 primitives and strings.
RandomAccessFile can be opened in read ("r") or read/write ("rw") mode. There is also an "rws" mode where the file is opened for read/write operations and every change to the file's data is immediately written to the physical device.
The OutputStream class is an abstract class that defines streaming byte output.
This category contains classes that define whether your data is going to a byte array (but not directly to a String; you are supposed to be able to create it from a byte array), to a file, or to a pipe.
Subclasses of the base class OutputStream:
PipedOutputStream - implements the concept of an output channel.
ObjectOutputStream - output stream for objects
FilterOutputStream is an abstract class that provides an interface for add-on classes that add useful properties to existing streams.
FileOutputStream - send data to a file on disk. Implementation of the OutputStream class.
DataOutputStream - An output stream that includes methods for writing standard Java data types.
ByteArrayOutputStream - Creates an in-memory buffer. All data sent to this stream is placed in the created buffer.
BufferedOutputStream - buffered output stream.
A type of buffering that reads a byte and then returns it to the stream. The PushbackInputStream class provides a mechanism to "look" into the input stream and see what will come from there next time without extracting information.
The class has an additional unread() method.
The SequenceInputStream class allows multiple instances of the InputStream class to be chained together. The constructor takes as an argument either a pair of objects of the InputStream class or the Enumeration interface.
During operation, the class makes requests to read from the first object of the InputStream class to the end, and then switches to the second. When using the interface, work will continue on all objects of the InputStream class. When the end of each file is reached, the associated stream is closed. Closing a stream created by an object of the SequenceInputStream class closes all open streams.
Subclasses of the Reader base class:
StringReader is an input stream reading from a string.
Reader is an abstract class that describes character input.
PushbackReader is an input stream that allows characters to be pushed back into the stream.
PipedReader - input channel.
LineNumberReader - an input stream that counts lines.
InputStreamReader - an input stream that translates bytes into characters.
FilterReader - filter reader.
FileReader is an input stream that reads a file.
CharArrayReader - an input stream that reads from a character array.
BufferedReader - buffered input character stream.
Subclasses of the Writer base class:
Writer - an abstract class that describes character output
StringWriter - the output stream writing to the string
PrintWriter - output stream including print() and println() methods
PipedWriter - the output pipe
OutputStreamWriter - output stream that translates bytes into characters
FilterWriter - filter writer
FileWriter - the output stream that writes to the file
CharArrayWriter - the output stream that writes to the character array
BufferedWriter - buffered output character stream
+
+
+
+
diff --git a/26 - ===== IO in Java Interview Preparation =====/002 Part 2 Java IO Interview - Questions and Answers.html b/26 - ===== IO in Java Interview Preparation =====/002 Part 2 Java IO Interview - Questions and Answers.html
new file mode 100644
index 0000000000000000000000000000000000000000..e3c941dae918064cd67c78428d138a3b357e3192
--- /dev/null
+++ b/26 - ===== IO in Java Interview Preparation =====/002 Part 2 Java IO Interview - Questions and Answers.html
@@ -0,0 +1,69 @@
+
+
+
+
+
+ Part 2 Java IO Interview - Questions and Answers
+
+
+
+
+
+
+
Part 2 Java IO Interview - Questions and Answers
+
An absolute path is a path that points to the same location in the file system, regardless of the current directory. The full path always starts from the root directory.
A relative path is a path relative to the current working directory.
The standard I/O classes in Java are in the java.io.* package. JDK 7 added a more modern way of working with threads called Java NIO or Java New IO, these classes are in the java.nio.* package. To work with archives, classes from the java.util.* package are used.
I/O wrapper classes are classes that add useful additional properties to existing streams.
Class examples: BufferedOutputStream, BufferedInputStrem, BufferedWriter , BufferedReader - buffer the stream and improve performance.
To read byte data (not strings), use the DataInputStream class. In this case, you must use the classes from the InputStream group.
The getBytes() method is provided in the String class to convert a string into an array of bytes suitable for putting into a ByteArrayInputStream. The resulting ByteArrayInputStream is an InputStream suitable for passing the DataInputStream.
When reading characters byte-by-byte from a formatted DataInputStream using the readByte() method, any value received will be considered valid, so the return value is not applicable to identify the end of the stream. Instead, you can use the available() method, which tells you how many characters are left.
The DataInputStream class allows you to read primitive data types from a stream through the DataInput interface, which defines methods that convert elementary values to a sequence of bytes. Such streams make it easy to store binary data in a file.
For this, classes are used that allow buffering the stream:
java.io.BufferedInputStream - buffered input stream. Constructors: BufferedInputStream(InputStream in), BufferedInputStream(InputStream in, int size).
java.io.BufferedOutputStream - buffered output stream. Constructors: BufferedOutputStream(OutputStream out), BufferedOutputStream(OutputStream out, int size).
java.io.BufferedReader - buffered input character stream. Constructors: BufferedReader(Reader r), BufferedReader(Reader in, int sz).
java.io.BufferedWriter - buffered output character stream. Constructors: BufferedWriter(Writer out), BufferedWriter(Writer out, int sz).
First of all, the PrintWriter class uses an improved way of working with UNICODE characters and a different output buffering mechanism.
In the PrintStream class, the output buffer was flushed whenever the print or println method was called. When using the PrintWriter class, you can disable automatically flushing buffers by doing it explicitly with the flush method.
The PrintWriter class provides two constructors that allow you to work with the output streams of the OutputStream class:
public PrintWriter(OutputStream out); - creates a stream without automatically flushing buffers.
public PrintWriter(OutputStream out, boolean autoFlush); - the way buffers are flushed when using the second constructor depends on the value of the autoFlush parameter. If it is true, automatic flushing of buffers is performed, and if it is false, it is not.
The set of implementations of the main print and println methods of the PrintWriter class is similar to the set of implementations of these methods of the PrintStream class.
Unlike most I/O classes, the File class does not work with streams, but directly with files. This class allows you to get information about the file: access rights, time and date of creation, directory path. And also to navigate through the hierarchies of subdirectories.
The java.io.File class can represent the name of a specific file, as well as the names of a group of files found in a directory. If the class represents a directory, then its list() method returns an array of strings with the names of all the files.
You can use one of the following constructors to create objects of the File class.
File(File dir, String name) - you specify object of class File (the directory where file is located) and file name are specified
File(String path) - specify the path to the file without specifying the file name
File(String dirPath, Sring name) - specifies the path to the file and the file name
File(URI url) - specifies the URI object describing the file
The delimiter symbol differs for different systems. You can pull it out from the property of the static field File.separator. For Windows it is "\".
The File class has a lot of methods, let's list some of them.
getAbsolutePath() - the absolute path of the file, starting from the system root. In Android, the root element is the slash character (/)
canRead() - verifies whether the file is available for reading
canWrite() - available for writing
exists() - file exists or not
getName() - returns the file name
getParent() - returns the name of the parent directory
getPath() - path
lastModified() - last modified date
isFile() - the object is a file, not a directory
isDirectory() - the object is a directory
isAbsolute() - returns true if the file has an absolute path
renameTo(File newPath) - Renames a file. The parameter specifies the name of the new file name. If the rename was unsuccessful, then false is returned.
delete() - deletes a file. You can also delete an empty directory
The FileFilter interface is used to check if a File object matches a certain condition. This interface contains a single boolean accept(File pathName) method. This method must be overridden and implemented.
DeflaterOutputStream, InflaterInputStream, ZipInputStream, ZipOutputStream, GZIPInputStream, GZIPOutputStream.
Serialization is the process of reading or writing an object. It is the process of saving the state of an object and reading that state. To implement serialization, you need to implement an interface - the Serializable marker interface. The reverse operation - translating bytes into an object, is called deserialization.
In order to exclude fields from the serializable stream, it is necessary to mark the field with the transient modifier.
Class properties marked with the transient modifier are not serialized. Typically, such fields store the intermediate state of the object, which, for example, is easier to calculate than to serialize and then deserialize. Another example of such a field is a reference to an instance of an object that does not require or cannot be serialized.
The private static final long serialVersionUID field contains the unique version identifier of the serialized class. It is calculated from the contents of the class - the fields, their declaration order, the methods, their declaration order. Accordingly, with any change in the class, this field will change its value.
This field is written to the stream when the class is serialized. By the way, this is perhaps the only known case when a static field is serialized.
The OutputStreamWriter is a bridge between the OutputStream class and the Writer class. Characters written to the stream are converted to bytes.
InputStreamReader - analogue for reading. Using the methods of the Reader class, bytes are read from the InputStream and then converted into characters.
In most cases, we do not define behavior manually, but rely on the standard implementation, and it is very inconvenient to constantly override some serialization methods + constantly monitor the addition of new fields, add them to methods. Well and specially for these purposes - there is Externalizable.
However, we know that you can change the default behavior of serialization by predefining and placing two methods in your class files:
private void writeObject(ObjectOutputStream out) throws IOException;
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException;
Note that both methods are declared private as this ensures that the methods are not overridden or overloaded. The whole trick is that the virtual machine, when calling the corresponding method, automatically checks if they were declared in the object class. The virtual machine can call the private methods of your class at any time, but other objects cannot. This ensures the integrity of the class and the normal operation of the serialization protocol.
Instead of implementing the Serializable interface, you can implement the Externalizable interface, which contains two methods:
public void writeExternal(ObjectOutput out) throws IOException;
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;
To create your own protocol, you just need to override these two methods. Unlike the other two serialization options, nothing is done automatically here. The protocol is completely in your hands. Although this is the most difficult method, it is also brings you the most controll over serialization process.
The problem is that after deserialization we will get another object. So serialization makes it possible to create a Singleton again, which is not what we want when we design singleton. Of course, you can forbid serializing Singletons, but this, in fact, is an avoidance of the problem, not a solution to it.
The solution is the following. The class defines a method with the following signature:
The access modifier can be private, protected, and default. The purpose of this method is to return a replacement object instead of the object on which it is called.
+
+
+
+
diff --git a/27 - Multithreading/001 Multithreading Overview_en.srt b/27 - Multithreading/001 Multithreading Overview_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..4bf05a54617ac6602390501b6fe2fef6677efb69
--- /dev/null
+++ b/27 - Multithreading/001 Multithreading Overview_en.srt
@@ -0,0 +1,740 @@
+1
+00:00:05,000 --> 00:00:11,000
+Hello, yes, students today will start learning a new topic, Moonface Riden, this is huge topic,
+
+2
+00:00:11,000 --> 00:00:16,000
+and after this course, you will have a lot of knowledge that you can apply in different programming
+
+3
+00:00:16,000 --> 00:00:21,000
+languages to support not just execution, but in scope of this course.
+
+4
+00:00:21,000 --> 00:00:27,000
+I will show you how MultiThreaded works on Java examples and take into account this is the first lesson
+
+5
+00:00:27,000 --> 00:00:32,000
+of new topic, this lesson a little bit more theoretical one to be sure that we have enough high level
+
+6
+00:00:32,000 --> 00:00:37,000
+knowledge and understanding before we'll start sharing, quote, examples in the next lesson.
+
+7
+00:00:37,000 --> 00:00:43,000
+That's why today we'll focus our attention on such questions as what is the process in our computers?
+
+8
+00:00:43,000 --> 00:00:45,000
+What is the threat of execution?
+
+9
+00:00:46,000 --> 00:00:52,000
+What is multithreaded in programming also in this lesson and explain how multiscreen works and what
+
+10
+00:00:52,000 --> 00:00:54,000
+threats and translation means.
+
+11
+00:00:54,000 --> 00:00:59,000
+And the standard answers on these questions will bring us to the point where we can discuss with you
+
+12
+00:00:59,000 --> 00:01:02,000
+why multiscreen is needed and what a benefit, something which is written.
+
+13
+00:01:03,000 --> 00:01:09,000
+And also we'll discuss dark side of multithreaded to understand it, drawbacks and what we should always
+
+14
+00:01:09,000 --> 00:01:12,000
+take into account while working as much as freedom.
+
+15
+00:01:12,000 --> 00:01:17,000
+And the end of the lesson, I will give you an overview of what packages and tools we are going to learn
+
+16
+00:01:17,000 --> 00:01:19,000
+in this course in JDK.
+
+17
+00:01:19,000 --> 00:01:25,000
+Answering all these questions will give you insights on what we are going to learn in this course.
+
+18
+00:01:25,000 --> 00:01:27,000
+I believe we are good with our agenda for today.
+
+19
+00:01:27,000 --> 00:01:34,000
+Let's start and before we even start discussion of multithreaded in the program, let's understand what
+
+20
+00:01:34,000 --> 00:01:36,000
+the process is in computer science.
+
+21
+00:01:36,000 --> 00:01:40,000
+In simple words, process is an instance of a computer program.
+
+22
+00:01:41,000 --> 00:01:42,000
+You opened a glimpse.
+
+23
+00:01:42,000 --> 00:01:45,000
+It's a separate process to run as a Java program.
+
+24
+00:01:46,000 --> 00:01:47,000
+Is that a separate Java process?
+
+25
+00:01:48,000 --> 00:01:53,000
+Computer program is nothing more than a set of instructions for a machine but process.
+
+26
+00:01:54,000 --> 00:01:56,000
+It is an execution of these instructions.
+
+27
+00:01:57,000 --> 00:02:00,000
+A process has a self-contained execution environment.
+
+28
+00:02:00,000 --> 00:02:04,000
+That means that each process has its own memory space.
+
+29
+00:02:05,000 --> 00:02:10,000
+And as I said before, usually processes and programs are considered to be very close terms.
+
+30
+00:02:11,000 --> 00:02:18,000
+But what end user interaction with may be a set of processes that interact with each other doing no
+
+31
+00:02:18,000 --> 00:02:21,000
+such popular Internet browser as Google Chrome?
+
+32
+00:02:21,000 --> 00:02:24,000
+So long to go home and look at the task manager.
+
+33
+00:02:25,000 --> 00:02:28,000
+You will see separate processes for each stop in your browser.
+
+34
+00:02:28,000 --> 00:02:33,000
+But for the end user, Manglehorn perceived like a single application.
+
+35
+00:02:33,000 --> 00:02:40,000
+This is because most operating system support interpersonal communication resources, sap, pipes and
+
+36
+00:02:40,000 --> 00:02:41,000
+sockets.
+
+37
+00:02:41,000 --> 00:02:47,000
+These resources are used to interact between different processes, homes, and this is pretty straightforward.
+
+38
+00:02:48,000 --> 00:02:51,000
+Now let's understand what threat of execution is.
+
+39
+00:02:51,000 --> 00:02:56,000
+Each process may be executed in one or more threats of execution.
+
+40
+00:02:56,000 --> 00:02:59,000
+In this case, our program is executed concurrently.
+
+41
+00:02:59,000 --> 00:03:03,000
+In other words, some instructions are executed in parallel.
+
+42
+00:03:03,000 --> 00:03:09,000
+In computer science, concurrency is a duplicate of different parts or units of a program algorithm
+
+43
+00:03:10,000 --> 00:03:17,000
+or problem to be executed out of order or at the same time simultaneously without affecting the final
+
+44
+00:03:17,000 --> 00:03:17,000
+outcome.
+
+45
+00:03:18,000 --> 00:03:22,000
+So we can say that each process may be executed in multiple threats.
+
+46
+00:03:23,000 --> 00:03:27,000
+In the learning literature, you might even find mention about different name of abstracts.
+
+47
+00:03:27,000 --> 00:03:34,000
+Sometimes they're called as lightweight processes or threats, share process resources.
+
+48
+00:03:34,000 --> 00:03:37,000
+This is something that may cause issues during the multithreaded.
+
+49
+00:03:38,000 --> 00:03:44,000
+If you're allocated two gigabytes for a GBM, that means all created stress will work within these two
+
+50
+00:03:44,000 --> 00:03:47,000
+gigabytes and we'll share in between each other.
+
+51
+00:03:48,000 --> 00:03:51,000
+Knowing your memory will be allocated to threat of execution.
+
+52
+00:03:52,000 --> 00:03:54,000
+I hope you already know the answer to my next question.
+
+53
+00:03:55,000 --> 00:03:56,000
+What is a move to threaten?
+
+54
+00:03:57,000 --> 00:04:01,000
+To threaten is the process of execution of program in multiple threats.
+
+55
+00:04:01,000 --> 00:04:04,000
+Most of the operating systems nowadays support this feature.
+
+56
+00:04:05,000 --> 00:04:11,000
+You have multiple course in your processa multithreaded allows you to use all course for execution of
+
+57
+00:04:11,000 --> 00:04:13,000
+your program instructions.
+
+58
+00:04:13,000 --> 00:04:21,000
+EPU executes one task at a time and we as the software engineers will write instructions how to split
+
+59
+00:04:22,000 --> 00:04:23,000
+between different threats of execution.
+
+60
+00:04:24,000 --> 00:04:25,000
+That's what we are going to learn.
+
+61
+00:04:26,000 --> 00:04:27,000
+Let me explain it now.
+
+62
+00:04:27,000 --> 00:04:32,000
+How multiscreen program works on the high level, you always have one threat of execution.
+
+63
+00:04:32,000 --> 00:04:34,000
+One program just started.
+
+64
+00:04:34,000 --> 00:04:36,000
+That is your main threat of execution.
+
+65
+00:04:37,000 --> 00:04:43,000
+After that, you can run so-called child threats of execution and describe instructions what those threats
+
+66
+00:04:43,000 --> 00:04:44,000
+should work on.
+
+67
+00:04:44,000 --> 00:04:48,000
+In parallel, the different use cases of using Otis Redding.
+
+68
+00:04:48,000 --> 00:04:49,000
+And we'll look at them in the minute.
+
+69
+00:04:50,000 --> 00:04:56,000
+And now the important thing, how to synchronize the work of different threats imagines at your peril
+
+70
+00:04:56,000 --> 00:04:58,000
+to your work between multiple threats.
+
+71
+00:04:59,000 --> 00:05:00,000
+It is another thing that.
+
+72
+00:05:00,000 --> 00:05:06,000
+All of the threats are part of one program, and sometimes threat needs to update on the man's threat
+
+73
+00:05:06,000 --> 00:05:09,000
+about state of execution or result of execution.
+
+74
+00:05:10,000 --> 00:05:15,000
+But sometimes threats also need to interact with each other, take into account all threats, working
+
+75
+00:05:15,000 --> 00:05:17,000
+with some shared resource.
+
+76
+00:05:17,000 --> 00:05:23,000
+To rephrase this in simple words, imagine that you have a collection of users and you need to filter
+
+77
+00:05:23,000 --> 00:05:28,000
+this collection and remove users that have less than one thousand dollars total.
+
+78
+00:05:28,000 --> 00:05:34,000
+Check in your online shop and you decided to split the task between different threats of execution.
+
+79
+00:05:34,000 --> 00:05:39,000
+Each threat of execution works with shared resource collection of users.
+
+80
+00:05:39,000 --> 00:05:46,000
+Each threat takes users from this common collection to provide the result of the specific part of namely
+
+81
+00:05:46,000 --> 00:05:53,000
+users are equally distributed between different threats but all threats to removing users from the common
+
+82
+00:05:53,000 --> 00:05:55,000
+collection shared between all of them.
+
+83
+00:05:55,000 --> 00:05:59,000
+Can you understand what the shared resource mean on this example?
+
+84
+00:06:00,000 --> 00:06:05,000
+Let's review also other use cases of multithreaded programming and the one we might want to use this
+
+85
+00:06:05,000 --> 00:06:05,000
+approach.
+
+86
+00:06:06,000 --> 00:06:08,000
+I believe that we have already discussed the first case.
+
+87
+00:06:09,000 --> 00:06:15,000
+That is the case when different threats on these slides are marked with capital key and numbers reaching
+
+88
+00:06:15,000 --> 00:06:22,000
+out to shared resource that is marked with capital are in this case to modify the state of the resource.
+
+89
+00:06:23,000 --> 00:06:27,000
+So next year's case of using multithreaded is reading and writing operations.
+
+90
+00:06:28,000 --> 00:06:33,000
+You know that in Java, most of the input output streams, blogs and in process of execution.
+
+91
+00:06:34,000 --> 00:06:37,000
+So why don't we use features of malicious reading?
+
+92
+00:06:37,000 --> 00:06:42,000
+And in case we need to write, let's say, some file, we do this in a separate thread.
+
+93
+00:06:42,000 --> 00:06:50,000
+For example, a user asked us to do an expert of all users to see format and wants to download this
+
+94
+00:06:50,000 --> 00:06:50,000
+info.
+
+95
+00:06:50,000 --> 00:06:52,000
+No problem at all.
+
+96
+00:06:52,000 --> 00:06:58,000
+We are writing a separate threat of execution and other parts of our program proceed, working without
+
+97
+00:06:58,000 --> 00:07:05,000
+any free's user still able to click on other buttons and perform other operations while file downloading
+
+98
+00:07:05,000 --> 00:07:06,000
+is in progress.
+
+99
+00:07:06,000 --> 00:07:07,000
+Is that clear?
+
+100
+00:07:07,000 --> 00:07:09,000
+Same situation with redundant info.
+
+101
+00:07:10,000 --> 00:07:16,000
+Let's create a separate threat of execution that will show a status of uploading, and once uploading
+
+102
+00:07:16,000 --> 00:07:21,000
+is finished, we will be notified about that fact and we'll proceed from there.
+
+103
+00:07:21,000 --> 00:07:27,000
+Pay attention to how your clips is working when your important project or performance some other operations.
+
+104
+00:07:28,000 --> 00:07:32,000
+Eclipse is also Java application was multithreaded feature inside.
+
+105
+00:07:32,000 --> 00:07:39,000
+When any operation is performed, UI is not completely blocked and you still can perform as operations
+
+106
+00:07:39,000 --> 00:07:40,000
+with the clips in parallel.
+
+107
+00:07:41,000 --> 00:07:47,000
+The third case is a case when once to produce some data and other thread consumes this data.
+
+108
+00:07:48,000 --> 00:07:54,000
+These threads are working independently and potentially may interact with the help of the queue between
+
+109
+00:07:54,000 --> 00:07:54,000
+each other.
+
+110
+00:07:55,000 --> 00:08:02,000
+On the slide here you can see that we have producer and consumer producer send some item ready for processing
+
+111
+00:08:02,000 --> 00:08:08,000
+to the queue and consumer take this item from the queue when ready to process the next item.
+
+112
+00:08:08,000 --> 00:08:12,000
+The next case is a typical scenario with writers and readers.
+
+113
+00:08:13,000 --> 00:08:19,000
+Imagine that you have some shared resource, some shared buffer, and from one side you have writers
+
+114
+00:08:19,000 --> 00:08:21,000
+that might be separate services.
+
+115
+00:08:21,000 --> 00:08:24,000
+Read that, write some information to the buffer.
+
+116
+00:08:24,000 --> 00:08:28,000
+It can be is a strong representation of new objects or requests to the app.
+
+117
+00:08:28,000 --> 00:08:30,000
+Literally everything.
+
+118
+00:08:30,000 --> 00:08:34,000
+And on the other side, you have readers that read data from the buffer.
+
+119
+00:08:35,000 --> 00:08:41,000
+This example is different from all previous ones that we have discussed because here we have some specific
+
+120
+00:08:41,000 --> 00:08:47,000
+conditions on the ones that can write to the buffer at the point of time readers can to read during
+
+121
+00:08:47,000 --> 00:08:53,000
+the writing, all the readers may read data simultaneously, will have similar tasks in this course.
+
+122
+00:08:53,000 --> 00:08:56,000
+And I will show you how to solve this task.
+
+123
+00:08:56,000 --> 00:08:58,000
+Really interesting, don't you think so?
+
+124
+00:08:59,000 --> 00:09:03,000
+Probably these are the most popular use cases of using an Otis Redding approach.
+
+125
+00:09:03,000 --> 00:09:10,000
+Definitely there will be variations of these use cases and sometimes even different scenarios, but
+
+126
+00:09:10,000 --> 00:09:13,000
+we'll try to cover as much as we can on this course.
+
+127
+00:09:13,000 --> 00:09:17,000
+Now let's discuss advantages and disadvantages of multi threading approach.
+
+128
+00:09:18,000 --> 00:09:20,000
+Let's start from advantages of multithreaded.
+
+129
+00:09:20,000 --> 00:09:22,000
+It was to name a few important ones.
+
+130
+00:09:22,000 --> 00:09:29,000
+They are effective use of multiple course of your processa, high performance of your program during
+
+131
+00:09:29,000 --> 00:09:32,000
+execution of specific operations and data processing.
+
+132
+00:09:33,000 --> 00:09:36,000
+Good to use with operations that block mansard of execution.
+
+133
+00:09:37,000 --> 00:09:43,000
+Like I said before, in case of working with input output streams, application responsiveness, if
+
+134
+00:09:43,000 --> 00:09:49,000
+there is a need to perform, some operation application won't be frozen until that operation is completed.
+
+135
+00:09:50,000 --> 00:09:53,000
+Instead, I will execute request in a separate thread.
+
+136
+00:09:54,000 --> 00:10:00,000
+Probably these are main advantages of using these advantages, maintaining the Australian approach.
+
+137
+00:10:00,000 --> 00:10:06,000
+Across all over the world and in different programming languages, but there are always two sides of
+
+138
+00:10:06,000 --> 00:10:10,000
+a metal, all these advantages come with a group of disadvantages.
+
+139
+00:10:10,000 --> 00:10:17,000
+Some of them are it is easy to use is written incorrectly by saying this, I would like to highlight
+
+140
+00:10:17,000 --> 00:10:18,000
+that using what is right.
+
+141
+00:10:18,000 --> 00:10:24,000
+And it requires a good understanding of the toolset to implement concurrent execution of your program.
+
+142
+00:10:24,000 --> 00:10:26,000
+And that is relatively easy to do.
+
+143
+00:10:26,000 --> 00:10:32,000
+A mistake, for example, in synchronous court, sometimes also of execution doesn't play a big role.
+
+144
+00:10:33,000 --> 00:10:39,000
+Or you can write code in different ways with the thread and it is not so easy and straightforward.
+
+145
+00:10:40,000 --> 00:10:46,000
+You need to be sure about what pieces of code you need to synchronize between different threads, how
+
+146
+00:10:46,000 --> 00:10:50,000
+much stress you need, how to split work between threads and so on.
+
+147
+00:10:50,000 --> 00:10:55,000
+Incorrect and suitable usage of Montasser in May cause your performance.
+
+148
+00:10:56,000 --> 00:11:00,000
+You need to understand that multithreaded works perfectly, not for all tasks.
+
+149
+00:11:01,000 --> 00:11:06,000
+For example, you might not always see the benefit of using what is written while working with small
+
+150
+00:11:06,000 --> 00:11:12,000
+data in case you want to implement a certain approach and filter an election was one hundred integers.
+
+151
+00:11:12,000 --> 00:11:18,000
+More likely, it will take more time than performing the same operation synchronously in one step.
+
+152
+00:11:19,000 --> 00:11:19,000
+Why?
+
+153
+00:11:20,000 --> 00:11:26,000
+Because running threads, synchronization time, corporatization of different threads on different CPUs.
+
+154
+00:11:26,000 --> 00:11:31,000
+All of this takes time and we need to be sure that when we apply to certain approach, it is really
+
+155
+00:11:31,000 --> 00:11:38,000
+worth it and we will benefit from this and some mistakes even can bring it to the deadlock and lifework
+
+156
+00:11:38,000 --> 00:11:39,000
+cases.
+
+157
+00:11:39,000 --> 00:11:45,000
+When your program doesn't perform any useful activity, hard to debark application and find the mistake,
+
+158
+00:11:46,000 --> 00:11:52,000
+it is much harder to replicate an error in the multithreaded application than it is to do so in a single
+
+159
+00:11:52,000 --> 00:11:53,000
+threaded application.
+
+160
+00:11:53,000 --> 00:11:58,000
+As a result, it is more difficult to identify and verify root causes when error.
+
+161
+00:11:58,000 --> 00:12:03,000
+Secure testing process of multithreaded app is more difficult.
+
+162
+00:12:03,000 --> 00:12:09,000
+Testing the multithreaded application is more difficult than testing a single application because the
+
+163
+00:12:09,000 --> 00:12:13,000
+effects are often timing related and more difficult to reproduce.
+
+164
+00:12:13,000 --> 00:12:19,000
+It is difficult to introduce notice writing approach already created code because all code needs to
+
+165
+00:12:19,000 --> 00:12:24,000
+be analyzed by engineers, static variables, methods and locations and critical areas.
+
+166
+00:12:24,000 --> 00:12:30,000
+Everything needs to be reviewed and adjusted to make sure that the implementation of concurrent programming
+
+167
+00:12:30,000 --> 00:12:32,000
+approach will not affect all application.
+
+168
+00:12:33,000 --> 00:12:39,000
+The main disadvantages of multithreaded that we also need to consider when we want to create scalable
+
+169
+00:12:39,000 --> 00:12:40,000
+app with high performance.
+
+170
+00:12:41,000 --> 00:12:47,000
+In this course, we are going to learn tools for concurrent programming most tools, classes and interfaces
+
+171
+00:12:47,000 --> 00:12:48,000
+allocated in Java.
+
+172
+00:12:48,000 --> 00:12:50,000
+You can current package.
+
+173
+00:12:50,000 --> 00:12:57,000
+This package also has some set packages, also some main types like Runnable and Thread located in general
+
+174
+00:12:57,000 --> 00:12:58,000
+and package.
+
+175
+00:12:58,000 --> 00:13:05,000
+But most of the classes and interfaces, including concurrent collections, locks and other mechanisms
+
+176
+00:13:05,000 --> 00:13:10,000
+for stress synchronization executer services and most of the things that we are going to learn allocated
+
+177
+00:13:10,000 --> 00:13:12,000
+individual concurrent package.
+
+178
+00:13:12,000 --> 00:13:15,000
+We have really a lot of interesting things to learn.
+
+179
+00:13:15,000 --> 00:13:19,000
+Now let's recap what we have learned in this lesson and this lesson.
+
+180
+00:13:19,000 --> 00:13:22,000
+We learned what the process is and what the threat is.
+
+181
+00:13:23,000 --> 00:13:28,000
+We also learned what is a multiscreen program programming now, you know, the most popular use cases
+
+182
+00:13:28,000 --> 00:13:30,000
+of not just training programs.
+
+183
+00:13:30,000 --> 00:13:34,000
+We learned advantages and disadvantages of concurrent programming.
+
+184
+00:13:35,000 --> 00:13:36,000
+That's all for this lesson.
+
+185
+00:13:36,000 --> 00:13:39,000
+Looking forward to seeing you in the next lesson.
+
diff --git a/27 - Multithreading/002 First Multithreading Program Thread & Runnable_en.srt b/27 - Multithreading/002 First Multithreading Program Thread & Runnable_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..20a6355a4f0a5d04f4186cb3e72ae290e35c266d
--- /dev/null
+++ b/27 - Multithreading/002 First Multithreading Program Thread & Runnable_en.srt
@@ -0,0 +1,1480 @@
+1
+00:00:05,000 --> 00:00:06,000
+Hello.
+
+2
+00:00:06,000 --> 00:00:09,000
+Yes, students in this class and will create our first multithreaded program.
+
+3
+00:00:10,000 --> 00:00:14,000
+It is time to put our theoretical knowledge on practice and learn new things.
+
+4
+00:00:14,000 --> 00:00:20,000
+We'll start from understanding of threat lifecycle and in which states our threat may be and when will
+
+5
+00:00:20,000 --> 00:00:22,000
+jump to practical examples.
+
+6
+00:00:22,000 --> 00:00:24,000
+You'll have enough knowledge to understand that.
+
+7
+00:00:25,000 --> 00:00:29,000
+And this lesson I will show you how to create a threat with five different ways.
+
+8
+00:00:29,000 --> 00:00:35,000
+We are going to learn such basic laws for multithreaded in general threat and one of the most important
+
+9
+00:00:35,000 --> 00:00:36,000
+interfaces.
+
+10
+00:00:36,000 --> 00:00:37,000
+Runnable.
+
+11
+00:00:37,000 --> 00:00:43,000
+While showing you examples, I will focus your attention on main properties of threat class to describe
+
+12
+00:00:43,000 --> 00:00:44,000
+each state.
+
+13
+00:00:44,000 --> 00:00:50,000
+And once we Iran's threats, we will learn with you how we can interact execution of a threat.
+
+14
+00:00:50,000 --> 00:00:56,000
+We'll discuss methods that are deprecated for a long time already and that you never should use.
+
+15
+00:00:56,000 --> 00:00:59,000
+And also we'll talk about proper ways of threat interaction.
+
+16
+00:01:00,000 --> 00:01:03,000
+Today, we're going to have a lot of good examples.
+
+17
+00:01:03,000 --> 00:01:09,000
+And as we will go over the examples, I will also explain specifics of some methods and behavior of
+
+18
+00:01:09,000 --> 00:01:09,000
+threats.
+
+19
+00:01:10,000 --> 00:01:10,000
+Let's start.
+
+20
+00:01:11,000 --> 00:01:17,000
+And as I said before, let's start from the understanding the whole lifecycle of a threat is considered
+
+21
+00:01:17,000 --> 00:01:18,000
+to be a new one.
+
+22
+00:01:18,000 --> 00:01:20,000
+We just created an object of a threat.
+
+23
+00:01:21,000 --> 00:01:23,000
+And you know that in Java, everything is an object.
+
+24
+00:01:24,000 --> 00:01:28,000
+That's why threat of execution is also an object to run a threat.
+
+25
+00:01:28,000 --> 00:01:35,000
+We need to start massive because mass that creates a separate threat of execution within the Java process.
+
+26
+00:01:36,000 --> 00:01:38,000
+After that threat is in the running state.
+
+27
+00:01:38,000 --> 00:01:44,000
+In this state, we can make our threat not run by turning our threat into waiting state or block state.
+
+28
+00:01:45,000 --> 00:01:50,000
+During this course, we will discuss all these scenarios, for example, when threat is blocked and
+
+29
+00:01:50,000 --> 00:01:57,000
+when it's waiting for now, you need just to understand that running threat may be put on pause and
+
+30
+00:01:57,000 --> 00:02:01,000
+getting back to running state again as engineers will learn how to do this.
+
+31
+00:02:02,000 --> 00:02:06,000
+Sometimes threats waiting their chance to update a shared resource.
+
+32
+00:02:06,000 --> 00:02:12,000
+Sometimes we want to make a threat, wait until other threats will adjust it of our shared resource.
+
+33
+00:02:12,000 --> 00:02:16,000
+And the last possible state of our threat is a Terminator's state.
+
+34
+00:02:16,000 --> 00:02:21,000
+This state tells us that threat finished its execution or it was interrupted.
+
+35
+00:02:22,000 --> 00:02:24,000
+Is it clear now when you're no threat?
+
+36
+00:02:24,000 --> 00:02:27,000
+Life-cycle it is time to write our first.
+
+37
+00:02:27,000 --> 00:02:32,000
+Just read an application I open file was named first just writing program.
+
+38
+00:02:32,000 --> 00:02:34,000
+I have main message here.
+
+39
+00:02:34,000 --> 00:02:37,000
+Let me go line by line and explain you each role here.
+
+40
+00:02:38,000 --> 00:02:44,000
+You can see that the first thing that I do here, I declare a variable of type Runnable and initialize
+
+41
+00:02:44,000 --> 00:02:46,000
+it with new object of type default.
+
+42
+00:02:46,000 --> 00:02:47,000
+Runnable.
+
+43
+00:02:47,000 --> 00:02:52,000
+Let me open source code of Runnable type, because you see this time the first time in this course,
+
+44
+00:02:53,000 --> 00:02:56,000
+as you can see, this is an interface from the Java version.
+
+45
+00:02:56,000 --> 00:03:01,000
+What does a functional interface was only one abasic mass with name.
+
+46
+00:03:01,000 --> 00:03:01,000
+Right.
+
+47
+00:03:02,000 --> 00:03:06,000
+We see that this method returns nassan and return type is void.
+
+48
+00:03:06,000 --> 00:03:13,000
+This is exactly the method that we need to implement and where we need to put a code that will be executed
+
+49
+00:03:13,000 --> 00:03:18,000
+in the separate thread to have separate thread, we need to have instructions about what this thread
+
+50
+00:03:18,000 --> 00:03:23,000
+is supposed to do and these instructions should be written somewhere.
+
+51
+00:03:23,000 --> 00:03:26,000
+This is exactly the method that will be executed by thread.
+
+52
+00:03:27,000 --> 00:03:33,000
+Let's now check the source code of a default runnable we see as a default Runnable implements Runnable
+
+53
+00:03:33,000 --> 00:03:34,000
+interface.
+
+54
+00:03:34,000 --> 00:03:41,000
+Basically, this is my custom clause that gives implementation to run Macel inside this matter.
+
+55
+00:03:41,000 --> 00:03:43,000
+I print such text to console.
+
+56
+00:03:43,000 --> 00:03:45,000
+I'm a new threat.
+
+57
+00:03:45,000 --> 00:03:52,000
+My name is and here I call static method on class will learn this class in a minute.
+
+58
+00:03:52,000 --> 00:03:58,000
+But just to finish explanation of this line, current threat is a static method of threat class that
+
+59
+00:03:58,000 --> 00:04:00,000
+returns the reference to the threat object.
+
+60
+00:04:01,000 --> 00:04:08,000
+And depending on where this method is invoked, we receive the reference to the object of current threat.
+
+61
+00:04:08,000 --> 00:04:13,000
+And after that I just call that name method that returns is a name of the threat.
+
+62
+00:04:13,000 --> 00:04:18,000
+I want to bring this text to console to prove that we have separate threat of execution.
+
+63
+00:04:18,000 --> 00:04:20,000
+One will run our app.
+
+64
+00:04:20,000 --> 00:04:24,000
+But before doing that, let's investigate threat glass.
+
+65
+00:04:24,000 --> 00:04:26,000
+Let me open the source code of this class.
+
+66
+00:04:27,000 --> 00:04:31,000
+The first thing is that you can notice here is that threat also implements Runnable.
+
+67
+00:04:32,000 --> 00:04:33,000
+What does this mean?
+
+68
+00:04:33,000 --> 00:04:38,000
+This means that the object of threat type also may be executed as a separate threat.
+
+69
+00:04:38,000 --> 00:04:42,000
+And this class also has implementation of around MassArt.
+
+70
+00:04:42,000 --> 00:04:43,000
+Let's look at it.
+
+71
+00:04:43,000 --> 00:04:49,000
+As we can see, the first things that object will try to do is to check whether we have target field
+
+72
+00:04:49,000 --> 00:04:49,000
+initialized.
+
+73
+00:04:49,000 --> 00:04:53,000
+And if yes, then we'll call run Masset on that object.
+
+74
+00:04:54,000 --> 00:04:57,000
+And if not, then we'll just do nothing.
+
+75
+00:04:57,000 --> 00:05:02,000
+Target Field has Runnable type and we can see even Kermanshah above this field.
+
+76
+00:05:02,000 --> 00:05:03,000
+This is something.
+
+77
+00:05:03,000 --> 00:05:08,000
+What will be around so as you can understand, we can do two things here.
+
+78
+00:05:08,000 --> 00:05:16,000
+We can pass Runnable object to the threat glass or we can override run Masad in Third-Class, we can
+
+79
+00:05:16,000 --> 00:05:18,000
+pass Runnable to this class.
+
+80
+00:05:18,000 --> 00:05:19,000
+We are constructor.
+
+81
+00:05:19,000 --> 00:05:23,000
+We have really a lot of different versions of constructor for this type.
+
+82
+00:05:23,000 --> 00:05:30,000
+And one of the constructor is to accept and initialize target field to store the reference to the Runnable
+
+83
+00:05:30,000 --> 00:05:30,000
+object.
+
+84
+00:05:31,000 --> 00:05:37,000
+Interesting thing to notice here is that this constructor invokes another version of constructor.
+
+85
+00:05:37,000 --> 00:05:39,000
+It passes in reference to the REDgroup.
+
+86
+00:05:40,000 --> 00:05:42,000
+We'll discuss a little bit later.
+
+87
+00:05:42,000 --> 00:05:48,000
+What does it reference to our Runnable object name of the thread, which consists of the word thread
+
+88
+00:05:48,000 --> 00:05:50,000
+dash and the sequential number.
+
+89
+00:05:50,000 --> 00:05:53,000
+Is it a static variable name thread in it?
+
+90
+00:05:53,000 --> 00:06:00,000
+No, that is incremented every time when the next threatener method and the last argument is a stack
+
+91
+00:06:00,000 --> 00:06:07,000
+size zero because according to the recommendation, in case this argument is zero, we have no requirement
+
+92
+00:06:07,000 --> 00:06:09,000
+for specific text size for this new threat.
+
+93
+00:06:10,000 --> 00:06:15,000
+And the new constructor Interent calls new constructor that passes to more arguments.
+
+94
+00:06:15,000 --> 00:06:23,000
+New and true new value is supposed to cover such constructor argument as access control context and
+
+95
+00:06:23,000 --> 00:06:29,000
+true value is the flag to indicate whether we need to inherit initial values for inheritable threat
+
+96
+00:06:29,000 --> 00:06:31,000
+logos from the construction threat.
+
+97
+00:06:32,000 --> 00:06:34,000
+Let me explain what these things meant.
+
+98
+00:06:35,000 --> 00:06:42,000
+Access control context is a type that is used to create objects that make system access decisions based
+
+99
+00:06:42,000 --> 00:06:44,000
+on the context it encapsulates.
+
+100
+00:06:44,000 --> 00:06:50,000
+Check permission Massada that is invoked in the context that access control context encapsulates inside
+
+101
+00:06:51,000 --> 00:06:56,000
+is allowed to process was access to resources or access control exception.
+
+102
+00:06:56,000 --> 00:07:00,000
+Anyway, this is not the topic for the first lesson of not just reading.
+
+103
+00:07:00,000 --> 00:07:04,000
+And this is not what you will use on a daily basis directly while working with me.
+
+104
+00:07:04,000 --> 00:07:05,000
+Just read it.
+
+105
+00:07:05,000 --> 00:07:07,000
+But just in order to let you know.
+
+106
+00:07:08,000 --> 00:07:10,000
+Regarding the second argument inherits read.
+
+107
+00:07:10,000 --> 00:07:13,000
+Locals do not pay a lot of attention to this one.
+
+108
+00:07:13,000 --> 00:07:20,000
+And this moment will cover concept of threat locals and inheritable threat local separately, but ensured
+
+109
+00:07:20,000 --> 00:07:26,000
+this flag is to tell threat whether we need to inherit values from inheritable threat local from the
+
+110
+00:07:26,000 --> 00:07:27,000
+construction threat.
+
+111
+00:07:27,000 --> 00:07:32,000
+And basically after that we proceed with construction of our threat of execution.
+
+112
+00:07:33,000 --> 00:07:38,000
+Besides the construction of Runnable that we have just discussed, we have also different constructors
+
+113
+00:07:38,000 --> 00:07:44,000
+that initializes other properties of threat object, for example, threat that takes Runnable and access
+
+114
+00:07:44,000 --> 00:07:51,000
+control context, constructor that takes REDgroup and Runnable also another popular constructor for
+
+115
+00:07:51,000 --> 00:07:54,000
+the bag and purposes is constructor with Runnable and string.
+
+116
+00:07:54,000 --> 00:08:00,000
+String represents the name of the threat and other different variations, including constructors with
+
+117
+00:08:00,000 --> 00:08:04,000
+taxes and boolean flag to indicate the state of the inherited threat.
+
+118
+00:08:04,000 --> 00:08:05,000
+The locals flag.
+
+119
+00:08:06,000 --> 00:08:07,000
+What are the properties?
+
+120
+00:08:07,000 --> 00:08:08,000
+The threat glass half.
+
+121
+00:08:09,000 --> 00:08:16,000
+If we would scroll to the top of this file, will find properties that we also may use during the configuration
+
+122
+00:08:16,000 --> 00:08:16,000
+of the threat.
+
+123
+00:08:17,000 --> 00:08:19,000
+You already know about threatening property.
+
+124
+00:08:20,000 --> 00:08:22,000
+By the way, here is also new keyword for you.
+
+125
+00:08:23,000 --> 00:08:24,000
+Volatile will cover it.
+
+126
+00:08:24,000 --> 00:08:28,000
+Do in the separate lesson we have priority property.
+
+127
+00:08:29,000 --> 00:08:35,000
+This is a from one to 10 that will be used by threat scheduler to decide what threat is more important
+
+128
+00:08:35,000 --> 00:08:36,000
+to work with.
+
+129
+00:08:36,000 --> 00:08:43,000
+So this next, however, we never can rely on the priority property when we have concurrent threat executed.
+
+130
+00:08:43,000 --> 00:08:49,000
+Let's call this recommendation, but not mandatory direction to follow for threats.
+
+131
+00:08:49,000 --> 00:08:50,000
+Catala What is a threat?
+
+132
+00:08:50,000 --> 00:08:54,000
+Skalla It is part of GM that decides which threats should run.
+
+133
+00:08:55,000 --> 00:08:58,000
+Also, it decides which threats should wait, how it is.
+
+134
+00:08:59,000 --> 00:09:03,000
+This is a great question, but probably not for the first practical move.
+
+135
+00:09:03,000 --> 00:09:06,000
+This riding lesson will also cover this topic separately.
+
+136
+00:09:07,000 --> 00:09:10,000
+The next property here is on by default.
+
+137
+00:09:10,000 --> 00:09:11,000
+It is false.
+
+138
+00:09:12,000 --> 00:09:16,000
+We will discuss later in this course what demons threats are interrupted.
+
+139
+00:09:16,000 --> 00:09:23,000
+Flag is used to indicate where the threat is interrupted and we need to stop its execution or we need
+
+140
+00:09:23,000 --> 00:09:25,000
+to proceed execution of a threat.
+
+141
+00:09:25,000 --> 00:09:26,000
+Let in this lesson.
+
+142
+00:09:26,000 --> 00:09:30,000
+I will also show you how to interact with this property.
+
+143
+00:09:31,000 --> 00:09:33,000
+Maxfield's here used by Jovian.
+
+144
+00:09:33,000 --> 00:09:36,000
+We will not focus our attention on them in this lesson.
+
+145
+00:09:37,000 --> 00:09:40,000
+And probably the one property that we did not talk yet is a threat.
+
+146
+00:09:40,000 --> 00:09:48,000
+The group this object is used to groups threats to gather in one group support group forms a three and
+
+147
+00:09:48,000 --> 00:09:50,000
+every threat except a regional threat.
+
+148
+00:09:50,000 --> 00:09:51,000
+The group has a parent.
+
+149
+00:09:52,000 --> 00:09:58,000
+There are also some specific self-locking mechanism for threat in that group, but probably will cover
+
+150
+00:09:58,000 --> 00:09:59,000
+this in a separate lesson.
+
+151
+00:10:00,000 --> 00:10:03,000
+And it looks like that Tetragon high level of.
+
+152
+00:10:03,000 --> 00:10:10,000
+You officer red class and its properties definitely as more things to learn here, but we'll do it gradually
+
+153
+00:10:10,000 --> 00:10:12,000
+and with practical examples, case by case.
+
+154
+00:10:13,000 --> 00:10:15,000
+Now, let's get back to the demo file here.
+
+155
+00:10:15,000 --> 00:10:20,000
+You can see that I created a threat object and positive reference to the Runnable object.
+
+156
+00:10:20,000 --> 00:10:25,000
+Why option was a separate class might be needed in this case.
+
+157
+00:10:25,000 --> 00:10:27,000
+You can declare some files if needed.
+
+158
+00:10:28,000 --> 00:10:34,000
+Also, you can declare constructors and pass external resources to the new objects if needed, because
+
+159
+00:10:34,000 --> 00:10:38,000
+by default, ranma, it doesn't take anything as Masset argument.
+
+160
+00:10:38,000 --> 00:10:43,000
+And here's just an example of constructor initialization of the state of this object.
+
+161
+00:10:44,000 --> 00:10:51,000
+If we want, we can pass any external object to the constructor and use the state of our runnable object
+
+162
+00:10:51,000 --> 00:10:53,000
+in one method if needed.
+
+163
+00:10:53,000 --> 00:10:58,000
+In such a way you can just share the resource that we shared with this thread.
+
+164
+00:10:59,000 --> 00:11:05,000
+This is basically the first way to create a threat object that is ready to be executed and that is in
+
+165
+00:11:05,000 --> 00:11:06,000
+your state.
+
+166
+00:11:06,000 --> 00:11:09,000
+The next way is another variation of the first one.
+
+167
+00:11:10,000 --> 00:11:15,000
+Instead of creating type that implements Runnable, we can just pass instance of anonymous class.
+
+168
+00:11:16,000 --> 00:11:19,000
+You can see here that I have similar method implemented.
+
+169
+00:11:20,000 --> 00:11:22,000
+Basically nothing special to highlight here.
+
+170
+00:11:23,000 --> 00:11:27,000
+And to be honest, this way of creating threat is not very popular.
+
+171
+00:11:28,000 --> 00:11:34,000
+The next way to great threat is to extend a new class from the threat and all around Massett, if you
+
+172
+00:11:34,000 --> 00:11:41,000
+remember when we were you in threat object, we saw that there is nothing to execute by default if we
+
+173
+00:11:41,000 --> 00:11:44,000
+didn't pass the reference to the Runnable object.
+
+174
+00:11:44,000 --> 00:11:48,000
+That's why so radically we can just override one method.
+
+175
+00:11:49,000 --> 00:11:54,000
+You can see that the current class extends threat clause and we overwrite one method here.
+
+176
+00:11:55,000 --> 00:12:00,000
+And after that, the main method is simply create the object of the first sorting program type.
+
+177
+00:12:01,000 --> 00:12:01,000
+That's it.
+
+178
+00:12:02,000 --> 00:12:08,000
+While this option often described in the literature, don't recommend it to you this way.
+
+179
+00:12:08,000 --> 00:12:08,000
+Why?
+
+180
+00:12:09,000 --> 00:12:13,000
+Because he extends that class just to overwrite one method.
+
+181
+00:12:13,000 --> 00:12:18,000
+Probably it is not the best approach from the single responsibility principle point of view.
+
+182
+00:12:19,000 --> 00:12:25,000
+For such purposes we have Runnable type and we can use it to give implementation to run Macit.
+
+183
+00:12:25,000 --> 00:12:32,000
+The fourth way to prepare a threat for execution is to use lambda expression to implement around Macit.
+
+184
+00:12:32,000 --> 00:12:34,000
+She can see that I created lambda function.
+
+185
+00:12:34,000 --> 00:12:37,000
+That takes no arguments and returns nassan.
+
+186
+00:12:38,000 --> 00:12:44,000
+Basically I just print the same text and the last, but not least for today, is the way preparing A
+
+187
+00:12:45,000 --> 00:12:46,000
+was MassArt reference.
+
+188
+00:12:46,000 --> 00:12:53,000
+I have a static method declared in this class with name execute that takes no parameters and that brings
+
+189
+00:12:53,000 --> 00:12:55,000
+the same text to cancel.
+
+190
+00:12:55,000 --> 00:13:00,000
+I just passing method reference here that meets the definition of Runnable interface.
+
+191
+00:13:00,000 --> 00:13:06,000
+It doesn't take any arguments and it returns nassan the same as around Massett.
+
+192
+00:13:06,000 --> 00:13:12,000
+In case you are not familiar with lambda functions and method references in Java, but you want to learn
+
+193
+00:13:12,000 --> 00:13:12,000
+that.
+
+194
+00:13:13,000 --> 00:13:16,000
+Check my functional programming course for Java InGenius.
+
+195
+00:13:16,000 --> 00:13:22,000
+We have really a lot of examples that the next thing that you see in this line and a sprinkling of the
+
+196
+00:13:22,000 --> 00:13:27,000
+current threat to console and for the sake of example, call run Nassib.
+
+197
+00:13:27,000 --> 00:13:36,000
+Remember, Run Masset doesn't start as a threat of execution, only start MassArt starts separate thread.
+
+198
+00:13:36,000 --> 00:13:42,000
+But if you would call directly around MassArt, you would just execute run MassArt synchronously.
+
+199
+00:13:43,000 --> 00:13:47,000
+And after that I call starts MassArt on each thread that we created here.
+
+200
+00:13:47,000 --> 00:13:53,000
+Let's run the program to see what we have got in the console in the first line with the printed text
+
+201
+00:13:53,000 --> 00:14:02,000
+from my main threat here you can see the text current threatening is and its name is Main Man is the
+
+202
+00:14:02,000 --> 00:14:09,000
+name of the first read that we have in our Java application is the next line is a result of invocation
+
+203
+00:14:09,000 --> 00:14:10,000
+of FRAND method.
+
+204
+00:14:10,000 --> 00:14:13,000
+And as you can see, threatening is still man.
+
+205
+00:14:13,000 --> 00:14:19,000
+That proves that invocation of method doesn't actually start a new threat.
+
+206
+00:14:20,000 --> 00:14:27,000
+And to start a new threat, we need to start Macit after you can see multiple lines with different names
+
+207
+00:14:27,000 --> 00:14:28,000
+of a threat.
+
+208
+00:14:29,000 --> 00:14:34,000
+That is exactly what is returned by getting the same method on the current threat involved from the
+
+209
+00:14:34,000 --> 00:14:35,000
+threat.
+
+210
+00:14:35,000 --> 00:14:42,000
+And you remember that by default, naming convention for each threat is threat word and sequential number
+
+211
+00:14:42,000 --> 00:14:42,000
+of a threat.
+
+212
+00:14:43,000 --> 00:14:47,000
+Can you understand now how to run your threat in real life?
+
+213
+00:14:47,000 --> 00:14:50,000
+You often use executor's to run and manage.
+
+214
+00:14:50,000 --> 00:14:53,000
+Your threats will learn executor's later in this course.
+
+215
+00:14:54,000 --> 00:15:00,000
+But what we have learned in this lesson, this is basics that you need to understand before moving further.
+
+216
+00:15:01,000 --> 00:15:02,000
+Now, what do we know how?
+
+217
+00:15:03,000 --> 00:15:08,000
+To start the threat, let's learn how to interact and stop its execution.
+
+218
+00:15:08,000 --> 00:15:16,000
+I have separate file for that was name interrupt them is interesting app that will help you to understand
+
+219
+00:15:16,000 --> 00:15:17,000
+how threat interception works.
+
+220
+00:15:18,000 --> 00:15:20,000
+Let's start from the main mast.
+
+221
+00:15:20,000 --> 00:15:24,000
+The first thing that I do here, create a task for execution.
+
+222
+00:15:24,000 --> 00:15:31,000
+I implement it runnable interface in this class for the sake of this demo and not having multiple classes
+
+223
+00:15:31,000 --> 00:15:31,000
+in this example.
+
+224
+00:15:32,000 --> 00:15:35,000
+I will show you around Massud in the minute after this.
+
+225
+00:15:35,000 --> 00:15:41,000
+I create a threat object and start a threat and I won't let the main threat sleep for two seconds and
+
+226
+00:15:41,000 --> 00:15:44,000
+interrupt my task after two seconds.
+
+227
+00:15:44,000 --> 00:15:45,000
+How I can do this?
+
+228
+00:15:46,000 --> 00:15:49,000
+I invoke sleep masset on the threat object.
+
+229
+00:15:49,000 --> 00:15:53,000
+This method takes a number of milliseconds as Masset argument.
+
+230
+00:15:54,000 --> 00:15:57,000
+Two seconds are equal to two thousand milliseconds.
+
+231
+00:15:57,000 --> 00:16:00,000
+Sleep method is our law that in threat class.
+
+232
+00:16:01,000 --> 00:16:02,000
+Let's look at the threat clause.
+
+233
+00:16:02,000 --> 00:16:03,000
+Source code.
+
+234
+00:16:03,000 --> 00:16:05,000
+We have to sleep massas here.
+
+235
+00:16:05,000 --> 00:16:12,000
+One was milliseconds only and another one takes two arguments, milliseconds and nanoseconds.
+
+236
+00:16:12,000 --> 00:16:14,000
+To be honest, I never used sleep mass.
+
+237
+00:16:14,000 --> 00:16:19,000
+It was nanoseconds, but still it is good to know that such method exists.
+
+238
+00:16:19,000 --> 00:16:26,000
+Let's get back to our demo file, another really user friendly interface of making sure that sleep is
+
+239
+00:16:26,000 --> 00:16:28,000
+to use time unit in from Javitz.
+
+240
+00:16:28,000 --> 00:16:29,000
+You can current package.
+
+241
+00:16:30,000 --> 00:16:36,000
+This enum represents time duration at the given unit of granularity and provides methods to convert
+
+242
+00:16:36,000 --> 00:16:40,000
+across units and perform timing and delay operations.
+
+243
+00:16:40,000 --> 00:16:47,000
+In these units, for example, you may perform such operations as making Meinzer slip, and the interface
+
+244
+00:16:47,000 --> 00:16:52,000
+allows us to not calculate milliseconds and convert them between seconds and other time units.
+
+245
+00:16:52,000 --> 00:16:53,000
+One unit.
+
+246
+00:16:53,000 --> 00:16:59,000
+But we can just take time units that we need and parse the value of the specific time unit that we need.
+
+247
+00:17:00,000 --> 00:17:03,000
+For example, here is a line similar to the one above.
+
+248
+00:17:04,000 --> 00:17:10,000
+It also uses milliseconds time unit and here is a line that use a second time unit.
+
+249
+00:17:10,000 --> 00:17:12,000
+And I'm just saying two seconds.
+
+250
+00:17:12,000 --> 00:17:16,000
+To be honest, in my opinion, using this API is more preferable.
+
+251
+00:17:17,000 --> 00:17:24,000
+And after this line, my main threat is in on the running state, in wait in state and the one threat
+
+252
+00:17:24,000 --> 00:17:26,000
+is awaiting as a threat may interrupt it.
+
+253
+00:17:27,000 --> 00:17:31,000
+That's why Slakey method maestro so called interrupted exception.
+
+254
+00:17:32,000 --> 00:17:39,000
+And that's why Compiler makes us handle this exception case to describe how a system should behave in
+
+255
+00:17:39,000 --> 00:17:41,000
+case somebody will interrupt this thread.
+
+256
+00:17:41,000 --> 00:17:46,000
+In this example, nobody will interrupt main threat but still interrupted.
+
+257
+00:17:46,000 --> 00:17:47,000
+Exception is checked.
+
+258
+00:17:47,000 --> 00:17:53,000
+That's why we need Searls declaration here in Maine method because for the sake of this demo, I don't
+
+259
+00:17:53,000 --> 00:17:55,000
+want to create try catch block here.
+
+260
+00:17:55,000 --> 00:17:59,000
+After that I print a console that I interact as a threat.
+
+261
+00:18:00,000 --> 00:18:01,000
+To interrupt as a threat.
+
+262
+00:18:01,000 --> 00:18:07,000
+We should call interrupt method interrupt method interruption flag inside the threat object.
+
+263
+00:18:08,000 --> 00:18:12,000
+That flag basically has two possible values, true or false.
+
+264
+00:18:12,000 --> 00:18:19,000
+With the help of this method, we can change the state of the interaction flag inside the threat and
+
+265
+00:18:19,000 --> 00:18:23,000
+the last line and my main threat is print and leave in the console.
+
+266
+00:18:23,000 --> 00:18:27,000
+Let's now look at our task and understand how interrupt.
+
+267
+00:18:27,000 --> 00:18:30,000
+Masset interrupts execution of the threat.
+
+268
+00:18:30,000 --> 00:18:32,000
+I open one method.
+
+269
+00:18:32,000 --> 00:18:39,000
+I print text that indicates that I entered one method and the threat is about to execute Vork method.
+
+270
+00:18:40,000 --> 00:18:41,000
+I invoke Vork method.
+
+271
+00:18:42,000 --> 00:18:43,000
+Let's look at it now.
+
+272
+00:18:44,000 --> 00:18:47,000
+Work method is that was the infinite loop.
+
+273
+00:18:47,000 --> 00:18:49,000
+After that we just print one word.
+
+274
+00:18:50,000 --> 00:18:52,000
+Verkin in f close.
+
+275
+00:18:52,000 --> 00:18:55,000
+I check if threat is interrupted is interrupted.
+
+276
+00:18:55,000 --> 00:19:02,000
+Matthew Chance is a state of the interaction flat and in case somebody from as a threat called MassArt
+
+277
+00:19:02,000 --> 00:19:07,000
+interrupt like we did in our main threat, then this method will return.
+
+278
+00:19:07,000 --> 00:19:07,000
+True.
+
+279
+00:19:08,000 --> 00:19:13,000
+Right now you already know what is done by interrupt and by is interrupted masses.
+
+280
+00:19:14,000 --> 00:19:16,000
+But why do we need interrupted?
+
+281
+00:19:16,000 --> 00:19:24,000
+Macit interrupted Massata returns also boolean value and return state of the interaction flac but it
+
+282
+00:19:24,000 --> 00:19:28,000
+also clears it and return it back to false.
+
+283
+00:19:28,000 --> 00:19:35,000
+So in case what uncommon this line and will executed interruption flag will be turned back to false
+
+284
+00:19:35,000 --> 00:19:36,000
+again.
+
+285
+00:19:36,000 --> 00:19:42,000
+To interrupt this thread I will keep this line commanded and we'll just leave it as an example for you.
+
+286
+00:19:42,000 --> 00:19:49,000
+By the way, I encourage you to download this service code example from the GitHub and run it locally
+
+287
+00:19:49,000 --> 00:19:49,000
+on your computer.
+
+288
+00:19:50,000 --> 00:19:55,000
+By doing this, you can play with values and comment and comment the lines that you are interested in
+
+289
+00:19:55,000 --> 00:20:00,000
+and as always, service code examples in attachments to this lesson.
+
+290
+00:20:00,000 --> 00:20:02,000
+OK, so now I believe.
+
+291
+00:20:03,000 --> 00:20:08,000
+The difference between these three methods interact is interrupted and interrupted.
+
+292
+00:20:08,000 --> 00:20:14,000
+Now pay attention that threat is moved to the white state because and will sleep mass at here.
+
+293
+00:20:14,000 --> 00:20:21,000
+And by the way, no matter how long sleep will be, I put one millisecond here for sleep.
+
+294
+00:20:21,000 --> 00:20:24,000
+But still, it is enough to interrupt the threat.
+
+295
+00:20:24,000 --> 00:20:25,000
+What will happen?
+
+296
+00:20:25,000 --> 00:20:28,000
+One threat will be a sleep take into account.
+
+297
+00:20:28,000 --> 00:20:35,000
+I'm in this safe block because interrupted FLAC is equal to true and the threat is invading state.
+
+298
+00:20:35,000 --> 00:20:38,000
+My threat will be interrupted and interrupted.
+
+299
+00:20:38,000 --> 00:20:40,000
+Exceptions will be thrown.
+
+300
+00:20:40,000 --> 00:20:48,000
+This line will not be executed never because interrupted exception will be thrown this mass Atheros
+
+301
+00:20:48,000 --> 00:20:52,000
+interrupted exception without any handlin to the upper level.
+
+302
+00:20:53,000 --> 00:20:58,000
+And here we should print interrupted in the work method and return from around Macit.
+
+303
+00:20:58,000 --> 00:21:05,000
+As you can see here, I have tried Kedge Block because sleep mass my throat checked exception and work
+
+304
+00:21:05,000 --> 00:21:08,000
+method doesn't handle this potential exception inside.
+
+305
+00:21:08,000 --> 00:21:11,000
+Let's run this program now for two seconds.
+
+306
+00:21:11,000 --> 00:21:18,000
+Program will bring to console working until threat will be interrupted and once it is interrupted,
+
+307
+00:21:18,000 --> 00:21:19,000
+let's see what we have.
+
+308
+00:21:19,000 --> 00:21:26,000
+The first thing that happened is threat interruption and even after that you can see that I printed
+
+309
+00:21:26,000 --> 00:21:27,000
+reconvert.
+
+310
+00:21:27,000 --> 00:21:34,000
+That is because I just changed interaction flac and I still need to wait until the threat will be in
+
+311
+00:21:34,000 --> 00:21:34,000
+a waiting mode.
+
+312
+00:21:35,000 --> 00:21:43,000
+This text in the main living tells us that Main Street finished its execution and after that we see
+
+313
+00:21:43,000 --> 00:21:44,000
+that we enter it if block.
+
+314
+00:21:44,000 --> 00:21:47,000
+And here is a status of interrupted flac.
+
+315
+00:21:47,000 --> 00:21:49,000
+It is equal to true.
+
+316
+00:21:49,000 --> 00:21:56,000
+The next step in our execution is entering the catch block and print and that threat was interrupted
+
+317
+00:21:56,000 --> 00:21:56,000
+in the work.
+
+318
+00:21:56,000 --> 00:21:57,000
+MassArt.
+
+319
+00:21:57,000 --> 00:21:58,000
+That's it.
+
+320
+00:21:59,000 --> 00:22:05,000
+So the rule of thumb, when you're creating all rain app, think about what is a logical point in your
+
+321
+00:22:05,000 --> 00:22:08,000
+thread to allow other threats to interrupt it.
+
+322
+00:22:08,000 --> 00:22:12,000
+In case you have such possibility to introduce this point, do it.
+
+323
+00:22:13,000 --> 00:22:16,000
+Usually you would let your threat fall asleep.
+
+324
+00:22:16,000 --> 00:22:21,000
+After all, resources are adjusted and state of the system is consistent.
+
+325
+00:22:21,000 --> 00:22:24,000
+In this case, there is no harm to interrupt the threat.
+
+326
+00:22:25,000 --> 00:22:31,000
+There are some methods that you should never use and that are marked as deprecated but not removed from
+
+327
+00:22:31,000 --> 00:22:34,000
+Janicki only because of the backwards compatibility.
+
+328
+00:22:34,000 --> 00:22:38,000
+Ziya, stop, suspend and resume.
+
+329
+00:22:39,000 --> 00:22:46,000
+These are dangerous masses in terms they are stop, suspend or resume threat execution instantly without
+
+330
+00:22:46,000 --> 00:22:47,000
+bothering.
+
+331
+00:22:47,000 --> 00:22:53,000
+What process is happening right now inside the threat, taking into account not all operations at ATOMIC
+
+332
+00:22:53,000 --> 00:22:57,000
+and performed with one single operation of updating data in the memory.
+
+333
+00:22:58,000 --> 00:23:01,000
+You can start somewhere in the middle of data processing in your threat.
+
+334
+00:23:02,000 --> 00:23:05,000
+At the meantime, resource will be updated as a threat.
+
+335
+00:23:05,000 --> 00:23:11,000
+And when you will resume execution, you may end up with not consistent state of your objects.
+
+336
+00:23:11,000 --> 00:23:18,000
+We will talk about atomic operations in adolescence, but I believe you understood that stopping a suspension
+
+337
+00:23:18,000 --> 00:23:25,000
+and after that resume and execution of the threat in case it is made some calculation process is not
+
+338
+00:23:25,000 --> 00:23:26,000
+the best idea.
+
+339
+00:23:26,000 --> 00:23:29,000
+And one more interesting and lasting for today's lesson.
+
+340
+00:23:30,000 --> 00:23:34,000
+Probably you saw one comment line here where I invoke June Masset.
+
+341
+00:23:35,000 --> 00:23:36,000
+What is it?
+
+342
+00:23:36,000 --> 00:23:40,000
+Let me uncommented first and run up one more time.
+
+343
+00:23:40,000 --> 00:23:44,000
+What's changed now in this version line?
+
+344
+00:23:44,000 --> 00:23:47,000
+Zatarain's in the main Leesville will always be printed.
+
+345
+00:23:47,000 --> 00:23:48,000
+Lost.
+
+346
+00:23:48,000 --> 00:23:49,000
+Why?
+
+347
+00:23:49,000 --> 00:23:56,000
+Because Join Masset also put our main threat in great state until this threat will be completely finished.
+
+348
+00:23:56,000 --> 00:23:59,000
+So I gave a command with this line to join.
+
+349
+00:23:59,000 --> 00:24:01,000
+This thread does a current one.
+
+350
+00:24:02,000 --> 00:24:08,000
+That's why my app will wait until Perry's threat will be completely executed during Masad.
+
+351
+00:24:08,000 --> 00:24:15,000
+Also, Masroor interrupted exception, taking into account it puts current threat wait in state and
+
+352
+00:24:15,000 --> 00:24:20,000
+other threats might interrupt this threat while it is innervate state.
+
+353
+00:24:20,000 --> 00:24:21,000
+Is it clear?
+
+354
+00:24:21,000 --> 00:24:25,000
+Basically, that's all what I wanted to share with you in this lesson.
+
+355
+00:24:26,000 --> 00:24:28,000
+Let's recap what we have learned today.
+
+356
+00:24:28,000 --> 00:24:34,000
+In this lesson, we learned the life cycle of the threat and how state of the threat is changed from
+
+357
+00:24:34,000 --> 00:24:36,000
+the new disseminated.
+
+358
+00:24:36,000 --> 00:24:39,000
+We learned five ways how to run a threat.
+
+359
+00:24:39,000 --> 00:24:43,000
+Also in this lesson, we performed over a year of threat class.
+
+360
+00:24:43,000 --> 00:24:48,000
+Now, you know, main properties of this type, we learned a radical interface.
+
+361
+00:24:48,000 --> 00:24:51,000
+Now you know how to use it to execute a separate threat.
+
+362
+00:24:52,000 --> 00:24:55,000
+And at the end of the lesson, we learned how to interrupt threat.
+
+363
+00:24:56,000 --> 00:24:59,000
+Hope you enjoyed the lesson and you like the examples.
+
+364
+00:24:59,000 --> 00:25:02,000
+We still have a lot of other things to learn, but.
+
+365
+00:25:02,000 --> 00:25:08,000
+I think that they will have enough information to remember, make sure you understand this lesson before
+
+366
+00:25:08,000 --> 00:25:12,000
+moving further, because multithreaded is not the easiest topic.
+
+367
+00:25:12,000 --> 00:25:18,000
+And we need to be very careful with understanding each concept in sequential order, because it would
+
+368
+00:25:18,000 --> 00:25:22,000
+be hard to understand one thing without understanding the previous one.
+
+369
+00:25:22,000 --> 00:25:23,000
+Thanks a lot for your attention.
+
+370
+00:25:24,000 --> 00:25:27,000
+Have a great day and see you in the next lesson.
+
diff --git a/27 - Multithreading/002 Source-code-of-the-First-multithreading-program.url b/27 - Multithreading/002 Source-code-of-the-First-multithreading-program.url
new file mode 100644
index 0000000000000000000000000000000000000000..ebed3f1dcb62f8d207a8859005b5c656966ddde8
--- /dev/null
+++ b/27 - Multithreading/002 Source-code-of-the-First-multithreading-program.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/FirstMultithreadingProgram.java
\ No newline at end of file
diff --git a/27 - Multithreading/002 Source-code-of-thread-interruption-demo.url b/27 - Multithreading/002 Source-code-of-thread-interruption-demo.url
new file mode 100644
index 0000000000000000000000000000000000000000..117fd076019b90deb1dd3e363ea63b9a9b92300f
--- /dev/null
+++ b/27 - Multithreading/002 Source-code-of-thread-interruption-demo.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/InterruptDemo.java
\ No newline at end of file
diff --git a/27 - Multithreading/003 Source-code-of-the-Priority-demo.url b/27 - Multithreading/003 Source-code-of-the-Priority-demo.url
new file mode 100644
index 0000000000000000000000000000000000000000..89ac0b8207a752a9dc091e6b0d38260381a3c324
--- /dev/null
+++ b/27 - Multithreading/003 Source-code-of-the-Priority-demo.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/PriorityDemo.java
\ No newline at end of file
diff --git a/27 - Multithreading/003 Source-code-of-the-Thread-group.url b/27 - Multithreading/003 Source-code-of-the-Thread-group.url
new file mode 100644
index 0000000000000000000000000000000000000000..cc64375a8ebf11890e906cb14352ca831313e244
--- /dev/null
+++ b/27 - Multithreading/003 Source-code-of-the-Thread-group.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/ThreadGroupDemo.java
\ No newline at end of file
diff --git a/27 - Multithreading/003 Source-code-of-the-daemon-threads.url b/27 - Multithreading/003 Source-code-of-the-daemon-threads.url
new file mode 100644
index 0000000000000000000000000000000000000000..8795edc73e8b0fa69d2d101a7d20471e42f34e98
--- /dev/null
+++ b/27 - Multithreading/003 Source-code-of-the-daemon-threads.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/DaemonThreadDemo.java
\ No newline at end of file
diff --git a/27 - Multithreading/003 Source-code-of-the-yield-method-demo.url b/27 - Multithreading/003 Source-code-of-the-yield-method-demo.url
new file mode 100644
index 0000000000000000000000000000000000000000..36ec18ea6f2caab2dd483676100bcb4c0191fdfc
--- /dev/null
+++ b/27 - Multithreading/003 Source-code-of-the-yield-method-demo.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/YieldDemo.java
\ No newline at end of file
diff --git a/27 - Multithreading/003 Source-code-of-throwing-exception-from-run-method-example.url b/27 - Multithreading/003 Source-code-of-throwing-exception-from-run-method-example.url
new file mode 100644
index 0000000000000000000000000000000000000000..be22d5bb4fa8b15f5a08e791032603ac92d9cea7
--- /dev/null
+++ b/27 - Multithreading/003 Source-code-of-throwing-exception-from-run-method-example.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/ThrowingExceptionFromRunnableDemo.java
\ No newline at end of file
diff --git a/27 - Multithreading/003 Thread Scheduler, Race Condition, Daemon Threads & Thread Groups_en.srt b/27 - Multithreading/003 Thread Scheduler, Race Condition, Daemon Threads & Thread Groups_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..d2d932440804f385113e4f05181f9a78034421b1
--- /dev/null
+++ b/27 - Multithreading/003 Thread Scheduler, Race Condition, Daemon Threads & Thread Groups_en.srt
@@ -0,0 +1,1128 @@
+1
+00:00:05,000 --> 00:00:10,000
+How came in this lesson, we're going to learn more about threats, the threats and threat groups,
+
+2
+00:00:11,000 --> 00:00:17,000
+basically that's what we have in our agenda for the day as we review these topics one by one, I will
+
+3
+00:00:17,000 --> 00:00:23,000
+also explain what's raised of condition is how priority works with threats and why do we need you to
+
+4
+00:00:23,000 --> 00:00:24,000
+MASSETT.
+
+5
+00:00:24,000 --> 00:00:29,000
+And also, at the end of this lesson, I will show you how we can throw an exception from the wrong
+
+6
+00:00:29,000 --> 00:00:30,000
+message.
+
+7
+00:00:30,000 --> 00:00:35,000
+And as always, we are going through different examples today that will help you to understand the topic
+
+8
+00:00:35,000 --> 00:00:36,000
+better.
+
+9
+00:00:36,000 --> 00:00:40,000
+All source code examples are in attachments to this lesson.
+
+10
+00:00:40,000 --> 00:00:41,000
+Let's start.
+
+11
+00:00:41,000 --> 00:00:44,000
+And the first thing that we are going to learn today is the threats.
+
+12
+00:00:44,000 --> 00:00:49,000
+Cédula in Paris, less than I already mentioned about threats Cédula and told you that this is part
+
+13
+00:00:49,000 --> 00:00:54,000
+of GM that decides which threats will be executed next and which threats should wait.
+
+14
+00:00:55,000 --> 00:01:00,000
+Also, I mentioned the threats CÉDULA, which is a threat that is in Runnable state.
+
+15
+00:01:00,000 --> 00:01:04,000
+That means the threat is running or waiting are blocked.
+
+16
+00:01:04,000 --> 00:01:10,000
+But imagine that you have multiple threats running right now and your computer doesn't have enough computing
+
+17
+00:01:10,000 --> 00:01:13,000
+capacity to start work on all threats at once.
+
+18
+00:01:14,000 --> 00:01:20,000
+So it's Canada will need to make a decision in such case, what threat to run first and which one should
+
+19
+00:01:20,000 --> 00:01:27,000
+go after was not an easy decision for a threat schedule, but how it would make a decision or what factors
+
+20
+00:01:27,000 --> 00:01:30,000
+will be part of the decision making process.
+
+21
+00:01:30,000 --> 00:01:32,000
+The first factor is priority.
+
+22
+00:01:32,000 --> 00:01:35,000
+The remember priority property from a threat class.
+
+23
+00:01:35,000 --> 00:01:42,000
+This is in the valley as it may be in range from one to ten is the high priority really should indicate
+
+24
+00:01:42,000 --> 00:01:49,000
+the threat that this threat should be prioritized over threats that have lower priority during the threat
+
+25
+00:01:49,000 --> 00:01:49,000
+of association.
+
+26
+00:01:50,000 --> 00:01:53,000
+New threat takes the same priority as parents threat.
+
+27
+00:01:54,000 --> 00:01:58,000
+Also, we have certain message that should help us to set new priorities if needed.
+
+28
+00:01:58,000 --> 00:01:59,000
+But what to do in this case?
+
+29
+00:01:59,000 --> 00:02:01,000
+Multiple threats have the same priority.
+
+30
+00:02:02,000 --> 00:02:06,000
+In this case, it is really hard to predict what would be the decision of threats.
+
+31
+00:02:06,000 --> 00:02:12,000
+Cédula that's why it is fair to make an assumption that random threat will be selected.
+
+32
+00:02:12,000 --> 00:02:19,000
+But we know that random is something human related only there is a programming code in place to make
+
+33
+00:02:19,000 --> 00:02:20,000
+a random decision.
+
+34
+00:02:20,000 --> 00:02:23,000
+We'll discuss this in the details later today.
+
+35
+00:02:23,000 --> 00:02:26,000
+And the second factor is in the arrival time.
+
+36
+00:02:26,000 --> 00:02:33,000
+Threats can also take into account the fact when threat arrived and how long each of them waited in
+
+37
+00:02:33,000 --> 00:02:36,000
+case with similar priority of threats.
+
+38
+00:02:36,000 --> 00:02:40,000
+Arrival time is one of the things that will be considered by threat schedule.
+
+39
+00:02:40,000 --> 00:02:44,000
+But again, this fact is not the final one in making the final decision.
+
+40
+00:02:45,000 --> 00:02:51,000
+So how the threats works, let's try to understand in a multi threat environment, multiple threats
+
+41
+00:02:51,000 --> 00:02:59,000
+executed concurrently, but processer allocates a small amount of time that is usually called time slice
+
+42
+00:02:59,000 --> 00:03:00,000
+through each threat.
+
+43
+00:03:01,000 --> 00:03:05,000
+So the task of threats CÉDULA is to verify each threat and make a decision.
+
+44
+00:03:06,000 --> 00:03:08,000
+What threat will get processers down first?
+
+45
+00:03:09,000 --> 00:03:13,000
+There is different scale algorithm used to answer this question.
+
+46
+00:03:13,000 --> 00:03:14,000
+Let's review them.
+
+47
+00:03:14,000 --> 00:03:16,000
+Preemptive priorities.
+
+48
+00:03:16,000 --> 00:03:20,000
+Keadilan this is algorithms that we partially discussed already.
+
+49
+00:03:20,000 --> 00:03:23,000
+Sweat's killer also at his highest priority.
+
+50
+00:03:24,000 --> 00:03:26,000
+The rest of the threats will be ignored.
+
+51
+00:03:26,000 --> 00:03:30,000
+But in this case, is it possible at all for other threats to be executed?
+
+52
+00:03:31,000 --> 00:03:31,000
+Yes.
+
+53
+00:03:32,000 --> 00:03:38,000
+In case as a threat has high priority or current threat, went to Washington state or was interrupted
+
+54
+00:03:38,000 --> 00:03:42,000
+or with the help of field marshal, what is yield massive?
+
+55
+00:03:42,000 --> 00:03:48,000
+This is akin to the scale of the current threat is willing to yield its current use of process and execution
+
+56
+00:03:48,000 --> 00:03:49,000
+time.
+
+57
+00:03:49,000 --> 00:03:52,000
+But the scandal is free to ignore this.
+
+58
+00:03:52,000 --> 00:03:57,000
+But to be honest regarding this particular matter, it is really appropriate to use it.
+
+59
+00:03:57,000 --> 00:04:00,000
+It may be usable for the bargain for testing purposes.
+
+60
+00:04:00,000 --> 00:04:07,000
+With my help to reproduce the race condition, we'll talk about what race condition is a little bit
+
+61
+00:04:07,000 --> 00:04:08,000
+later in this lesson.
+
+62
+00:04:08,000 --> 00:04:11,000
+The next algorithm is first come, first serve.
+
+63
+00:04:11,000 --> 00:04:13,000
+Scheduling rules are simple here.
+
+64
+00:04:14,000 --> 00:04:20,000
+Zaretsky assigns CPU time to the threads that appear to be the one who requested it first.
+
+65
+00:04:21,000 --> 00:04:23,000
+Also, we shouldn't forget about slice and schedule.
+
+66
+00:04:24,000 --> 00:04:28,000
+You already understood that piece of time for each thread is called a time slice.
+
+67
+00:04:28,000 --> 00:04:35,000
+Each thread gets executed cyclically one after another as Reskin will track where the threads finished.
+
+68
+00:04:35,000 --> 00:04:38,000
+His execution was in a time slice or no in case.
+
+69
+00:04:38,000 --> 00:04:43,000
+Yes, this threat will be removed from CU and Schoettler will work with other threats.
+
+70
+00:04:43,000 --> 00:04:45,000
+Only is it clear.
+
+71
+00:04:46,000 --> 00:04:50,000
+Now let's check how all these algorithms work together on the simple example.
+
+72
+00:04:51,000 --> 00:04:54,000
+Imagine that we have five threads and only one processor.
+
+73
+00:04:55,000 --> 00:04:59,000
+Let's make an assumption that all threats have different priorities and different arrival time.
+
+74
+00:05:00,000 --> 00:05:01,000
+The together that uses.
+
+75
+00:05:02,000 --> 00:05:07,000
+Algorithms that we have discussed, it will decide which thread to select to give a time of crisis.
+
+76
+00:05:08,000 --> 00:05:14,000
+At first, Zaretsky should select the highest priority and in case of a threat, was high priority with
+
+77
+00:05:14,000 --> 00:05:16,000
+request access to processer.
+
+78
+00:05:17,000 --> 00:05:24,000
+Then you will get access to the CPU during the first opportunity and once will deal with the same priority
+
+79
+00:05:24,000 --> 00:05:28,000
+Skidder will use first come first serve scale algorithms to those threats.
+
+80
+00:05:29,000 --> 00:05:33,000
+So hope now you have the vision how threats are executed in the current environment.
+
+81
+00:05:34,000 --> 00:05:40,000
+Now let me quickly explain what is the condition then, multiple definitions of this term.
+
+82
+00:05:41,000 --> 00:05:46,000
+Let me share with you, some of them in some sort of serious condition is explained like I can issue
+
+83
+00:05:46,000 --> 00:05:53,000
+an error in multistorey and program design when program execution depends on the sequence of Seurat's
+
+84
+00:05:53,000 --> 00:05:54,000
+execution.
+
+85
+00:05:54,000 --> 00:06:00,000
+The error guernseys name from the similar mistake in electronic circuit design signals race.
+
+86
+00:06:01,000 --> 00:06:07,000
+And as a leader, you may find definitions of race condition as not an issue, but as a state of the
+
+87
+00:06:07,000 --> 00:06:14,000
+system where substantive behavior of an application is dependent on the sequence or of other events.
+
+88
+00:06:15,000 --> 00:06:20,000
+So is it an issue or just a state without any consequences and without any impact?
+
+89
+00:06:21,000 --> 00:06:25,000
+Actually, race condition may cause various impact on your execution.
+
+90
+00:06:26,000 --> 00:06:27,000
+Let's review some of them.
+
+91
+00:06:27,000 --> 00:06:34,000
+Memory leak and controlled access to the common memory during the race condition, mainly due to having
+
+92
+00:06:34,000 --> 00:06:35,000
+memory leak.
+
+93
+00:06:35,000 --> 00:06:39,000
+It can visit memory that is needed is not released by some thread.
+
+94
+00:06:39,000 --> 00:06:42,000
+For example, inconsistent data.
+
+95
+00:06:42,000 --> 00:06:48,000
+It may happen that both threads managed to get access to the same resource and one of the mistakes of
+
+96
+00:06:48,000 --> 00:06:50,000
+concurrent interaction happened.
+
+97
+00:06:50,000 --> 00:06:56,000
+Probably one thread of data to resource was one value, but another threat overrides its value with
+
+98
+00:06:56,000 --> 00:06:56,000
+new one.
+
+99
+00:06:57,000 --> 00:07:02,000
+And you have lost update or for example, once to use a resource to read data from it.
+
+100
+00:07:02,000 --> 00:07:08,000
+But in the meantime, in parallel as a threat, updating this resource and the first resource with our
+
+101
+00:07:08,000 --> 00:07:10,000
+data data, this is called virtual.
+
+102
+00:07:11,000 --> 00:07:13,000
+It is also possible to face other issues.
+
+103
+00:07:14,000 --> 00:07:18,000
+But I believe you understand the potential impact for data consistency in your app.
+
+104
+00:07:19,000 --> 00:07:22,000
+Dedlock and liveblog is a separate lesson.
+
+105
+00:07:22,000 --> 00:07:25,000
+I will show you examples of Dedlock and liveblog.
+
+106
+00:07:25,000 --> 00:07:30,000
+Ensure this situation in your app decreased productivity of each threat to zero.
+
+107
+00:07:31,000 --> 00:07:32,000
+Is that technically working?
+
+108
+00:07:32,000 --> 00:07:38,000
+But they don't produce any results and also there might be other impacts caused by race conditions.
+
+109
+00:07:39,000 --> 00:07:43,000
+So these are just a few potential impacts that you may face with Ingres.
+
+110
+00:07:43,000 --> 00:07:46,000
+Conditions state how to avoid race condition.
+
+111
+00:07:47,000 --> 00:07:53,000
+We can avoid risk conditions by building proper synchronization in critical sections of execution.
+
+112
+00:07:53,000 --> 00:07:59,000
+DigiCam provides different ways for stress synchronization, and we'll run them in a separate lessons.
+
+113
+00:07:59,000 --> 00:08:02,000
+We learned a lot of new things for the day.
+
+114
+00:08:02,000 --> 00:08:07,000
+Let's start practical part of our lesson and review the source code of our examples.
+
+115
+00:08:07,000 --> 00:08:09,000
+Let's start from priority to demo.
+
+116
+00:08:09,000 --> 00:08:15,000
+I was shown now that you know I should count on property property as we discussed.
+
+117
+00:08:15,000 --> 00:08:20,000
+Yes, it will be considered, but take into account that might be different cases.
+
+118
+00:08:21,000 --> 00:08:25,000
+When threat arrived and ready for execution, one processor time is available.
+
+119
+00:08:25,000 --> 00:08:32,000
+The greatest threat and one processor ready to process said a lot of things happen literally in milliseconds.
+
+120
+00:08:32,000 --> 00:08:35,000
+I have files, as is called priority demo.
+
+121
+00:08:35,000 --> 00:08:36,000
+What do we have here?
+
+122
+00:08:37,000 --> 00:08:39,000
+We have static MassArt with name executes it.
+
+123
+00:08:39,000 --> 00:08:44,000
+I will use to create objects of a threat that this is a similar method, the one we had in previous
+
+124
+00:08:44,000 --> 00:08:45,000
+demo.
+
+125
+00:08:45,000 --> 00:08:48,000
+I just bring the name of the threat to console.
+
+126
+00:08:48,000 --> 00:08:53,000
+I create five threats and pay attention to the naming convention of the variables.
+
+127
+00:08:53,000 --> 00:08:55,000
+I'm starting indexing from zero.
+
+128
+00:08:56,000 --> 00:09:00,000
+This will help us to match variable name and threatening and cancel.
+
+129
+00:09:00,000 --> 00:09:04,000
+I use certain method to set different priorities, can use threats.
+
+130
+00:09:04,000 --> 00:09:07,000
+You can see the threat zero has the lowest priority.
+
+131
+00:09:07,000 --> 00:09:13,000
+So I want to have the highest priority and the rest of threats also have different priorities here.
+
+132
+00:09:14,000 --> 00:09:20,000
+Also, you need to know that threat clause has different constants already to separate the three constants.
+
+133
+00:09:20,000 --> 00:09:27,000
+The main priority that is equal to one naum priority is equal to five and max priorities.
+
+134
+00:09:27,000 --> 00:09:28,000
+That is equal to that.
+
+135
+00:09:29,000 --> 00:09:32,000
+You can use this constant in setting masses if you want.
+
+136
+00:09:32,000 --> 00:09:39,000
+And after all these configurations, I run my app, I will run it multiple times, try to pay attention
+
+137
+00:09:39,000 --> 00:09:43,000
+to what stories will be printed to console first and what will be printed last.
+
+138
+00:09:44,000 --> 00:09:50,000
+And you can see that in most cases read no one is printed most of the times to console in the first
+
+139
+00:09:50,000 --> 00:09:50,000
+row.
+
+140
+00:09:50,000 --> 00:09:56,000
+And the strange thing is that a threat to that is also brought it then maybe printed the last one.
+
+141
+00:09:57,000 --> 00:09:59,000
+So something strange is happening here.
+
+142
+00:09:59,000 --> 00:10:00,000
+Threads it has.
+
+143
+00:10:00,000 --> 00:10:05,000
+Highest priority and not the last arrival time will be painted the last one.
+
+144
+00:10:06,000 --> 00:10:08,000
+Why was the magic is happening here?
+
+145
+00:10:09,000 --> 00:10:10,000
+You're right.
+
+146
+00:10:10,000 --> 00:10:12,000
+This is magic of concurrent execution.
+
+147
+00:10:12,000 --> 00:10:18,000
+Imagine that you have multiple tasks at once, great threads, running threads, synchronized access
+
+148
+00:10:18,000 --> 00:10:19,000
+to the Queensland method.
+
+149
+00:10:20,000 --> 00:10:21,000
+And we'll get to synchronization soon.
+
+150
+00:10:22,000 --> 00:10:28,000
+And you will learn that Sprint alone is synchronized and time slices for each thread are not infinite.
+
+151
+00:10:28,000 --> 00:10:35,000
+And while a lot of things happen, not always our brains can understand why we see this result, but
+
+152
+00:10:35,000 --> 00:10:36,000
+not the last one.
+
+153
+00:10:37,000 --> 00:10:38,000
+But at least my brain for sure.
+
+154
+00:10:38,000 --> 00:10:40,000
+Not always can understand this.
+
+155
+00:10:40,000 --> 00:10:45,000
+But anyway, this is what you should know about MultiThreaded before you start creating lots of training
+
+156
+00:10:45,000 --> 00:10:46,000
+programs.
+
+157
+00:10:46,000 --> 00:10:50,000
+You can't always predict the sequence of execution.
+
+158
+00:10:50,000 --> 00:10:51,000
+That's why.
+
+159
+00:10:51,000 --> 00:10:51,000
+Will it always?
+
+160
+00:10:51,000 --> 00:10:58,000
+You have to create programs that will not depend on the sequence of execution with race condition and
+
+161
+00:10:58,000 --> 00:11:01,000
+unexpected impact on the results of our application.
+
+162
+00:11:02,000 --> 00:11:07,000
+Now, when I show you that you shouldn't completely rely on priority property, let me also show you
+
+163
+00:11:07,000 --> 00:11:08,000
+another thing.
+
+164
+00:11:08,000 --> 00:11:11,000
+This time I'll show you the massive example.
+
+165
+00:11:11,000 --> 00:11:13,000
+We have two threats.
+
+166
+00:11:13,000 --> 00:11:19,000
+The first threat gives a hint of threats, cédula that the threat is ready to yield its current use
+
+167
+00:11:19,000 --> 00:11:22,000
+of a processor and after that freeze its name.
+
+168
+00:11:23,000 --> 00:11:26,000
+The second threat, Princetonian of the threat straight away.
+
+169
+00:11:27,000 --> 00:11:28,000
+I believe this is clear.
+
+170
+00:11:28,000 --> 00:11:34,000
+Let's execute our app multiple times and we can see that output is not deterministic.
+
+171
+00:11:35,000 --> 00:11:39,000
+Sometimes zero is printed to console first and sometimes otherwise.
+
+172
+00:11:40,000 --> 00:11:44,000
+It looks like it doesn't make a lot of sense whether I'm using static method.
+
+173
+00:11:44,000 --> 00:11:51,000
+You know, we can even make an assumption that access to such a centralized method as printer land is
+
+174
+00:11:51,000 --> 00:11:55,000
+random no matter what they use method or no.
+
+175
+00:11:55,000 --> 00:12:00,000
+That's why in documentation, it's clearly written that threats cannot ignore this hint.
+
+176
+00:12:01,000 --> 00:12:08,000
+And all my life I ask different people multiple times the question why isn't we need to yield massive
+
+177
+00:12:08,000 --> 00:12:09,000
+and broad use?
+
+178
+00:12:09,000 --> 00:12:13,000
+They don't bring us to the same expected result every time.
+
+179
+00:12:13,000 --> 00:12:19,000
+And I been answered, like I explained to you, different algorithms, time slicing, and probably even
+
+180
+00:12:19,000 --> 00:12:20,000
+the business world can yield massive.
+
+181
+00:12:21,000 --> 00:12:24,000
+The chances are different to execute one or another threat.
+
+182
+00:12:24,000 --> 00:12:31,000
+But in real life and in Damos cases, it is almost impossible to visualize the benefit of this methods.
+
+183
+00:12:31,000 --> 00:12:36,000
+Unfortunately, that is something that you should know about Lucas writing in Paris last month when
+
+184
+00:12:36,000 --> 00:12:43,000
+we performed an overview of a threat glass and I promised you to explain what demon threats are actually
+
+185
+00:12:43,000 --> 00:12:45,000
+are not so much things to here.
+
+186
+00:12:46,000 --> 00:12:48,000
+Jim is stopped once.
+
+187
+00:12:48,000 --> 00:12:50,000
+There are only demons, rats running.
+
+188
+00:12:50,000 --> 00:12:56,000
+This is very useful to great demon threats, like supporters of another threat, for example, in case
+
+189
+00:12:56,000 --> 00:13:03,000
+when demons can't exist without us a threat because it's not so important without another threat.
+
+190
+00:13:03,000 --> 00:13:10,000
+In one of home tasks, I would ask you to create demon threats that will recent events in another thread.
+
+191
+00:13:10,000 --> 00:13:12,000
+And in the case there is known as a threat.
+
+192
+00:13:12,000 --> 00:13:14,000
+There is nothing to listen.
+
+193
+00:13:14,000 --> 00:13:16,000
+I know from demons, threats, demon class.
+
+194
+00:13:17,000 --> 00:13:22,000
+I create a thread that contains infinite loop and brings the demon is in each half of the second.
+
+195
+00:13:23,000 --> 00:13:30,000
+I start the thread and make my mind sweat sleep for two seconds and after that I pray that the main
+
+196
+00:13:30,000 --> 00:13:31,000
+threat is finished.
+
+197
+00:13:31,000 --> 00:13:34,000
+I will keep this land commanded for the first round.
+
+198
+00:13:35,000 --> 00:13:41,000
+I run the program and as you can see, even after two seconds and even after my strength was finished
+
+199
+00:13:41,000 --> 00:13:48,000
+and Nasrat is still working, the only way for me to stop it now is to stop Jaba process.
+
+200
+00:13:49,000 --> 00:13:50,000
+I press the stop sign here.
+
+201
+00:13:51,000 --> 00:13:53,000
+Let's do another thing now.
+
+202
+00:13:53,000 --> 00:13:54,000
+I have a lot in common.
+
+203
+00:13:54,000 --> 00:14:03,000
+This line I call set a massive here and set jemal flat to true now key once thread is demon and will
+
+204
+00:14:03,000 --> 00:14:05,000
+be stopped right after the threat is created.
+
+205
+00:14:05,000 --> 00:14:10,000
+It will be finished because after the threats have created it will be finished.
+
+206
+00:14:10,000 --> 00:14:12,000
+Only demons wrath will stay.
+
+207
+00:14:12,000 --> 00:14:20,000
+And considering the fact that one of the demon threats you will stop execution the generals or machine
+
+208
+00:14:20,000 --> 00:14:25,000
+exits and stop execution when the only threats is running at all demon threats.
+
+209
+00:14:25,000 --> 00:14:30,000
+Let's run our app now and we can see that once main threat is finished.
+
+210
+00:14:30,000 --> 00:14:32,000
+Jimmy, I am a stop.
+
+211
+00:14:32,000 --> 00:14:37,000
+Is it clear hope that this example helped you to understand what demons rates are?
+
+212
+00:14:38,000 --> 00:14:42,000
+Also, in previous lesson I promised to show you how to work with different groups.
+
+213
+00:14:43,000 --> 00:14:43,000
+In this lesson.
+
+214
+00:14:43,000 --> 00:14:46,000
+I also prepare them file to share it with you.
+
+215
+00:14:46,000 --> 00:14:48,000
+Let me remind you what social group?
+
+216
+00:14:48,000 --> 00:14:51,000
+S Support group is a set of threats.
+
+217
+00:14:51,000 --> 00:14:57,000
+The threat group forms that we in which every group except the initial threat group has apparent its
+
+218
+00:14:57,000 --> 00:15:00,000
+threat is allowed to access information about.
+
+219
+00:15:00,000 --> 00:15:06,000
+Its own strength group, but not the access information about its groups, parents or the group or any
+
+220
+00:15:06,000 --> 00:15:11,000
+other group, this that helps us to manage a group of threats as a single unit.
+
+221
+00:15:11,000 --> 00:15:17,000
+This is extremely valuable when you want to perform such operations as interrupt, for example, for
+
+222
+00:15:17,000 --> 00:15:19,000
+all threats, I will not lie to you.
+
+223
+00:15:19,000 --> 00:15:22,000
+And I'm going to say that this type is not very popular today.
+
+224
+00:15:23,000 --> 00:15:28,000
+In this search code, you can find and mentions a certain group is pretty old type that was created
+
+225
+00:15:28,000 --> 00:15:30,000
+in Java version one.
+
+226
+00:15:30,000 --> 00:15:36,000
+That's why I don't see a lot of sense to go over each message here and show you an example for each
+
+227
+00:15:36,000 --> 00:15:41,000
+Massett, because it is very less likely that you will use this class in production.
+
+228
+00:15:41,000 --> 00:15:47,000
+But still, I believe it was me sharing it with you for general educational purposes, at least on the
+
+229
+00:15:47,000 --> 00:15:52,000
+high level, because programming languages is constantly improved and new types are introduced.
+
+230
+00:15:53,000 --> 00:15:59,000
+But core principles are the same and understand in such basics as this class will help you to grasp
+
+231
+00:15:59,000 --> 00:16:00,000
+new knowledge faster.
+
+232
+00:16:01,000 --> 00:16:02,000
+I open them a file.
+
+233
+00:16:03,000 --> 00:16:10,000
+The first things that I do in this example, Ikarus object basically very different constructors.
+
+234
+00:16:10,000 --> 00:16:15,000
+You can create a group with name or person as interest groups are supposed to be a parent for the new
+
+235
+00:16:15,000 --> 00:16:15,000
+one.
+
+236
+00:16:16,000 --> 00:16:22,000
+And then after that I create multiple threats and possible reference to the third group in constructor.
+
+237
+00:16:22,000 --> 00:16:28,000
+Also, I incommensurable interface by persons, a reference to the execute method so each threat will
+
+238
+00:16:28,000 --> 00:16:31,000
+have infinite loop and it will print its name.
+
+239
+00:16:31,000 --> 00:16:37,000
+Each half of the second and once read will be interrupted while sleeping will break the loop.
+
+240
+00:16:37,000 --> 00:16:38,000
+In main method.
+
+241
+00:16:38,000 --> 00:16:45,000
+I start all threads and make my main thread sleep for two seconds and after that I don't need to interrupt
+
+242
+00:16:45,000 --> 00:16:46,000
+each thread separately.
+
+243
+00:16:47,000 --> 00:16:54,000
+But instead I look into wrapped method on a select group and I expect all threads in this group will
+
+244
+00:16:54,000 --> 00:16:54,000
+be interrupted.
+
+245
+00:16:55,000 --> 00:16:59,000
+Let's run this program and see what we have and the result is expected.
+
+246
+00:17:00,000 --> 00:17:04,000
+We interrupted all threads and broke infinite loop jam is stopped.
+
+247
+00:17:05,000 --> 00:17:11,000
+This is how easily I can interact with a group of threads with the help of threads, group type and
+
+248
+00:17:11,000 --> 00:17:16,000
+the last bit on the list sink for this lesson that I wanted to share with you is how to throw exceptions
+
+249
+00:17:16,000 --> 00:17:17,000
+from the Runnable.
+
+250
+00:17:17,000 --> 00:17:23,000
+If you remember, one method in Runnable interface doesn't declare that it makes any exception.
+
+251
+00:17:24,000 --> 00:17:29,000
+This is exactly the reason why we should handle all checked exceptions inside are unnecessary.
+
+252
+00:17:29,000 --> 00:17:35,000
+But what if you don't know how to handle specific exception and you need to throw the exception according
+
+253
+00:17:35,000 --> 00:17:37,000
+to a logic, how to be in this case?
+
+254
+00:17:38,000 --> 00:17:42,000
+There is a dirty trick that you can do if needed to throw exceptions from the run.
+
+255
+00:17:43,000 --> 00:17:44,000
+Pay attention.
+
+256
+00:17:44,000 --> 00:17:46,000
+You can't leave without handloom.
+
+257
+00:17:46,000 --> 00:17:51,000
+Check the exceptions, but nobody set any restrictions on unchecked exceptions.
+
+258
+00:17:52,000 --> 00:17:53,000
+They understand what I mean.
+
+259
+00:17:53,000 --> 00:17:58,000
+We'll wrap our checked exception in and check in our example.
+
+260
+00:17:58,000 --> 00:18:03,000
+You can see how I tried to imitate IO exception by putting illegal pasta sauce.
+
+261
+00:18:03,000 --> 00:18:06,000
+I catch the exception and throw a new one.
+
+262
+00:18:06,000 --> 00:18:13,000
+This time I throw runtime exception and I pass an exception to a constructor like a course of the exception.
+
+263
+00:18:13,000 --> 00:18:16,000
+Let's execute this thread and see what we have.
+
+264
+00:18:16,000 --> 00:18:17,000
+Great.
+
+265
+00:18:17,000 --> 00:18:23,000
+You have runtime exception which caused by no such file exception and now you're Lowgar will be able
+
+266
+00:18:23,000 --> 00:18:30,000
+to grab this looks to the proper and actual issues that will help you during investigation and debugging
+
+267
+00:18:30,000 --> 00:18:31,000
+in the future.
+
+268
+00:18:32,000 --> 00:18:36,000
+The information about those exceptional will help you to understand the reason of threat interruption.
+
+269
+00:18:37,000 --> 00:18:40,000
+That's all what I wanted to share with you in this lesson.
+
+270
+00:18:40,000 --> 00:18:43,000
+Let's recap what we have learned in this lesson.
+
+271
+00:18:44,000 --> 00:18:45,000
+Is this lesson learned?
+
+272
+00:18:45,000 --> 00:18:48,000
+What is a threat scandal and how it works now?
+
+273
+00:18:48,000 --> 00:18:54,000
+You know what race condition is and what potential impact it can bring in this course, we'll learn
+
+274
+00:18:54,000 --> 00:18:56,000
+how to deal with race condition.
+
+275
+00:18:56,000 --> 00:19:02,000
+Also, I showed you an example of how property property impacts and the threat and execution and how
+
+276
+00:19:02,000 --> 00:19:04,000
+your message works.
+
+277
+00:19:04,000 --> 00:19:10,000
+We learned what the threats are and examples I showed you how you can manipulate a group of threats
+
+278
+00:19:10,000 --> 00:19:11,000
+with a group object.
+
+279
+00:19:12,000 --> 00:19:16,000
+And at the end of the lesson, I show you how we can throw exemption from randomness.
+
+280
+00:19:17,000 --> 00:19:18,000
+That's it for this lesson.
+
+281
+00:19:18,000 --> 00:19:20,000
+Thanks a lot for your attention.
+
+282
+00:19:20,000 --> 00:19:23,000
+Have a great day and see you in the next lesson.
+
diff --git a/27 - Multithreading/004 Source-code-of-all-examples-from-the-lesson.url b/27 - Multithreading/004 Source-code-of-all-examples-from-the-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..c59b6698e29473c38fc2fd5f6f4268496db38785
--- /dev/null
+++ b/27 - Multithreading/004 Source-code-of-all-examples-from-the-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/waitnotify
\ No newline at end of file
diff --git a/27 - Multithreading/004 Synchronization Basics_en.srt b/27 - Multithreading/004 Synchronization Basics_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..cbfbe78883b136d11cf407e151c48b998bd6fe49
--- /dev/null
+++ b/27 - Multithreading/004 Synchronization Basics_en.srt
@@ -0,0 +1,1532 @@
+1
+00:00:05,000 --> 00:00:09,000
+How are the students in this lesson, we are going to learn the basics of synchronization.
+
+2
+00:00:10,000 --> 00:00:14,000
+Synchronization is a huge topic and we'll learn it with you during multiple lessons.
+
+3
+00:00:15,000 --> 00:00:20,000
+This is the first lesson about stress and presentations that will give you basic knowledge when you
+
+4
+00:00:20,000 --> 00:00:22,000
+create concurrent programs.
+
+5
+00:00:22,000 --> 00:00:28,000
+One of the most important things that you should care about is a synchronized access of multiple threats
+
+6
+00:00:28,000 --> 00:00:29,000
+to the critical errors.
+
+7
+00:00:30,000 --> 00:00:36,000
+What is critical sections will learn with you today in this lesson also will learn with your concepts
+
+8
+00:00:36,000 --> 00:00:37,000
+of monitor and mutex.
+
+9
+00:00:38,000 --> 00:00:43,000
+After this lesson, you will understand these two concepts where, well, I will explain to you what
+
+10
+00:00:43,000 --> 00:00:46,000
+is at tormey cooperation and what is not.
+
+11
+00:00:46,000 --> 00:00:53,000
+Once you understand, all this theory will jump to practical examples and will create our first program
+
+12
+00:00:53,000 --> 00:00:54,000
+with synchronized threats.
+
+13
+00:00:54,000 --> 00:01:00,000
+I will explain how a synchronized keyboard works with Marcedes, and at the end of the lesson I will
+
+14
+00:01:00,000 --> 00:01:04,000
+explain such methods as a way to notify and notify all.
+
+15
+00:01:04,000 --> 00:01:07,000
+All objects in Java have these methods.
+
+16
+00:01:07,000 --> 00:01:09,000
+Let's start to begin with.
+
+17
+00:01:09,000 --> 00:01:12,000
+Let's understand what a critical section is.
+
+18
+00:01:12,000 --> 00:01:18,000
+It is important for us to learn this first because the rest of what we are going to do in this lesson
+
+19
+00:01:18,000 --> 00:01:21,000
+is to synchronize access to critical sections.
+
+20
+00:01:21,000 --> 00:01:25,000
+That's why understanding of this term is critically important.
+
+21
+00:01:25,000 --> 00:01:32,000
+Imagine that you have multiple threats that are executed concurrently and there is block of code that
+
+22
+00:01:32,000 --> 00:01:36,000
+theoretically may be available simultaneously for two threats.
+
+23
+00:01:36,000 --> 00:01:43,000
+This means that in some point of time it might happen that two or more threats will interact with some
+
+24
+00:01:43,000 --> 00:01:49,000
+resource simultaneously that may cause mistakes in calculations and data.
+
+25
+00:01:49,000 --> 00:01:50,000
+Inconsistency.
+
+26
+00:01:50,000 --> 00:01:57,000
+In other words, critical section is a group of instructions that should be executed concurrently only
+
+27
+00:01:57,000 --> 00:02:01,000
+by a specific number of threats and performance specific operations.
+
+28
+00:02:01,000 --> 00:02:08,000
+Usually it is one threat, but as we keep learning to read into advanced level, you would understand
+
+29
+00:02:08,000 --> 00:02:11,000
+that sometimes we want to allow multiple threats to perform.
+
+30
+00:02:11,000 --> 00:02:16,000
+One operation was a resource and allow multiple threats to perform another operation.
+
+31
+00:02:16,000 --> 00:02:22,000
+For example, imagine that you have collection, let's say a list operation of the new elements, or
+
+32
+00:02:22,000 --> 00:02:25,000
+at least should not allow other threats.
+
+33
+00:02:25,000 --> 00:02:32,000
+Read value from any index at mass should block access for all of the threats to read elements from specific
+
+34
+00:02:32,000 --> 00:02:38,000
+index, because I can add new element in that position and that would cause there to be read by other
+
+35
+00:02:38,000 --> 00:02:39,000
+threats.
+
+36
+00:02:39,000 --> 00:02:46,000
+At the same time, there is no need to look at the threats in case all threats only read data from my
+
+37
+00:02:46,000 --> 00:02:49,000
+array list and don't change its state.
+
+38
+00:02:50,000 --> 00:02:57,000
+That's why I may allow as many threats as there exist to read data from our own list only until the
+
+39
+00:02:57,000 --> 00:03:01,000
+moment of adding new elements to contain that will count does it make sense.
+
+40
+00:03:02,000 --> 00:03:05,000
+Now let's understand what is an atomic operation.
+
+41
+00:03:05,000 --> 00:03:07,000
+Atomic comes from Greek word atom.
+
+42
+00:03:08,000 --> 00:03:12,000
+That literally means uncuttable in computer science.
+
+43
+00:03:12,000 --> 00:03:17,000
+Atomic operation is operations that is performed with single processing cycle.
+
+44
+00:03:17,000 --> 00:03:21,000
+In other words, atomic operation is an interrupted operation.
+
+45
+00:03:22,000 --> 00:03:23,000
+Let's understand this, an example.
+
+46
+00:03:24,000 --> 00:03:29,000
+Imagine that you perform an increment of your object's property and you want to update its state.
+
+47
+00:03:30,000 --> 00:03:34,000
+What this thing is, this atomic operation, it is not.
+
+48
+00:03:34,000 --> 00:03:35,000
+Why?
+
+49
+00:03:35,000 --> 00:03:40,000
+Because you have to read values that are stored in the piece of memory dictated to the class property
+
+50
+00:03:40,000 --> 00:03:41,000
+variable first.
+
+51
+00:03:42,000 --> 00:03:46,000
+After that you need to perform an increment and add one.
+
+52
+00:03:46,000 --> 00:03:51,000
+After that, you need to store the result of additions in some place, and only after that you need
+
+53
+00:03:51,000 --> 00:03:55,000
+to assign the result of increments to another variable.
+
+54
+00:03:55,000 --> 00:03:57,000
+Our class property is that clear.
+
+55
+00:03:58,000 --> 00:04:04,000
+So even such simple operation is the first glance like increment is not atomic, but in this case,
+
+56
+00:04:05,000 --> 00:04:07,000
+what is an atomic operation?
+
+57
+00:04:07,000 --> 00:04:09,000
+And simple words read and write.
+
+58
+00:04:09,000 --> 00:04:11,000
+Operations are atomic.
+
+59
+00:04:11,000 --> 00:04:18,000
+For example, assigning value to a variable is atomic operation removal value from array is atomic operation.
+
+60
+00:04:18,000 --> 00:04:21,000
+Assigning value is an atomic operation too.
+
+61
+00:04:22,000 --> 00:04:29,000
+Does it make sense also in general with a special package that contains only Tibs that execute not atomic
+
+62
+00:04:29,000 --> 00:04:35,000
+operations by nature, but actually execute operations that looks like atomic, for example?
+
+63
+00:04:36,000 --> 00:04:41,000
+You know, that increment and addition is not atomic operation by itself, but atomic integer, for
+
+64
+00:04:41,000 --> 00:04:48,000
+example, maybe from addition of another in synchronized manner to not allow any other threat interrupt
+
+65
+00:04:48,000 --> 00:04:55,000
+execution of the separation later in this course, will review is generally two concurrent atomic package
+
+66
+00:04:55,000 --> 00:04:58,000
+that contains such types of perform atomic operations.
+
+67
+00:04:59,000 --> 00:05:03,000
+Would it a great single ready now you know what is an atomic.
+
+68
+00:05:03,000 --> 00:05:07,000
+Atomic operations also know what a critical section is.
+
+69
+00:05:07,000 --> 00:05:12,000
+Let's look at example now so that you can understand the problem of performing non atomic operations
+
+70
+00:05:12,000 --> 00:05:19,000
+with multiple threats and why we need to synchronize access to critical section I open unsynchronized
+
+71
+00:05:19,000 --> 00:05:20,000
+incremented file.
+
+72
+00:05:20,000 --> 00:05:22,000
+Let's look at the main message here.
+
+73
+00:05:22,000 --> 00:05:29,000
+And I will say you before we start that the quote below is a spaghetti code because we don't use executer
+
+74
+00:05:29,000 --> 00:05:34,000
+in this example, considering the fact that by this moment in our course, we don't know.
+
+75
+00:05:34,000 --> 00:05:40,000
+Executor's, I will show you this example was BASIX, Red Cross and Runnable interface that we all know
+
+76
+00:05:41,000 --> 00:05:46,000
+later in this course, we'll show you another solution, which is, in my opinion, more elegant.
+
+77
+00:05:46,000 --> 00:05:53,000
+But I will show it to you once we execute our stoppered hacker, at least that will contain references
+
+78
+00:05:53,000 --> 00:06:00,000
+to ohmy threat objects, because I'm going to create 10000 thread objects when it's so many threads
+
+79
+00:06:00,000 --> 00:06:07,000
+objects to be able to demo issues that may happen in case with performing on atomic operation with multiple
+
+80
+00:06:07,000 --> 00:06:09,000
+threats have falu.
+
+81
+00:06:09,000 --> 00:06:11,000
+And you can see that in condition.
+
+82
+00:06:11,000 --> 00:06:16,000
+I verify that I made 10000 iterations on each iteration.
+
+83
+00:06:16,000 --> 00:06:21,000
+I create a new threat object with the following implementation of Runnable interface.
+
+84
+00:06:21,000 --> 00:06:27,000
+I increment my static int variables that is present in this class and I will perform this increment
+
+85
+00:06:27,000 --> 00:06:29,000
+10000 times.
+
+86
+00:06:29,000 --> 00:06:37,000
+So what value will be here once all threats will perform increment ten thousand times will look at the
+
+87
+00:06:37,000 --> 00:06:43,000
+answer in the minutes after that and look at reference of this threat to the common list of threats.
+
+88
+00:06:43,000 --> 00:06:50,000
+I need this to be able to request each threat to join main threat and make main threat, wait until
+
+89
+00:06:50,000 --> 00:06:52,000
+all other threats will be executed.
+
+90
+00:06:53,000 --> 00:07:00,000
+And again, you need to see this code to feel relief later when you will start to use executer, because
+
+91
+00:07:00,000 --> 00:07:05,000
+you will understand how executables would simplify interaction with multiple threats.
+
+92
+00:07:05,000 --> 00:07:09,000
+And in Body of the Loop, I start each threat after that.
+
+93
+00:07:09,000 --> 00:07:14,000
+And for each loop I ask each threat, the join main threat and make my main threat.
+
+94
+00:07:14,000 --> 00:07:18,000
+Wait until all other threats will be executed.
+
+95
+00:07:18,000 --> 00:07:24,000
+When all threats did incremented, we can print our variable to cancel and let's see.
+
+96
+00:07:24,000 --> 00:07:28,000
+Instead I will run program multiple times to let you see the issue.
+
+97
+00:07:29,000 --> 00:07:32,000
+Can you see that the result is not always 10000?
+
+98
+00:07:33,000 --> 00:07:35,000
+They understand why this is happening.
+
+99
+00:07:36,000 --> 00:07:43,000
+That is because at some moment of time, two threats enter this method simultaneously and both threats
+
+100
+00:07:43,000 --> 00:07:48,000
+read the same value of counter variable and each threat might increment.
+
+101
+00:07:48,000 --> 00:07:51,000
+But logically, this is two increments.
+
+102
+00:07:51,000 --> 00:07:58,000
+But in fact, once we get our right increment result from as a threat and we got lost update, is it
+
+103
+00:07:58,000 --> 00:08:02,000
+clear now and what to do and how to solve this issue?
+
+104
+00:08:02,000 --> 00:08:05,000
+You already can easily spot where critical section is.
+
+105
+00:08:06,000 --> 00:08:12,000
+We need to synchronize access of different threats to our critical section where we are careful not
+
+106
+00:08:12,000 --> 00:08:13,000
+optronics operation.
+
+107
+00:08:14,000 --> 00:08:20,000
+That's why I started the lesson from explanation of critical sections and atomic operations to make
+
+108
+00:08:20,000 --> 00:08:25,000
+sure that by this moment of time in our lesson, you would understand what I'm talking about.
+
+109
+00:08:25,000 --> 00:08:28,000
+Let's now try to solve this issue.
+
+110
+00:08:28,000 --> 00:08:35,000
+To solve this issue, we need to control concurrent access to the critical area, the basic to enjoy.
+
+111
+00:08:35,000 --> 00:08:37,000
+The key for this is synchronized keyword.
+
+112
+00:08:38,000 --> 00:08:40,000
+Let me open synchronized increment class.
+
+113
+00:08:41,000 --> 00:08:45,000
+This is similar example to the previous one was only one difference.
+
+114
+00:08:45,000 --> 00:08:48,000
+My increment method synchronized keyword here.
+
+115
+00:08:49,000 --> 00:08:51,000
+Let's run our program now multiple times.
+
+116
+00:08:51,000 --> 00:08:59,000
+And you can see now that I constantly have ten thousand and so is it is because this synchronized keyword
+
+117
+00:08:59,000 --> 00:09:03,000
+doesn't allow to stress access is block of code simultaneously.
+
+118
+00:09:04,000 --> 00:09:07,000
+That's why we just eliminated all possible errors.
+
+119
+00:09:07,000 --> 00:09:10,000
+How to synchronize keywords for X.
+
+120
+00:09:10,000 --> 00:09:14,000
+We need to understand this to create more complex solutions with better performance.
+
+121
+00:09:15,000 --> 00:09:21,000
+To understand how to synchronize keyboard works, we need to understand such important concepts in Montessori,
+
+122
+00:09:21,000 --> 00:09:24,000
+in programming as mutex and monitor.
+
+123
+00:09:24,000 --> 00:09:27,000
+Let's start from understanding of what Moneta is.
+
+124
+00:09:28,000 --> 00:09:33,000
+And once we learned what I wanted to ask, how explain the difference between the index and monitor
+
+125
+00:09:34,000 --> 00:09:36,000
+my own definition of monitor.
+
+126
+00:09:36,000 --> 00:09:42,000
+Sounds like this monitor is a mechanism to synchronize threads, access to critical sections.
+
+127
+00:09:43,000 --> 00:09:50,000
+More common definition from Wikipedia also includes other properties of monitor like ability to allow
+
+128
+00:09:50,000 --> 00:09:55,000
+stress to have both mutuel exclusion and the ability to wait for a critical condition.
+
+129
+00:09:56,000 --> 00:10:02,000
+By the way, mutuel exclusion is also churl from computer science and describes the property of.
+
+130
+00:10:02,000 --> 00:10:09,000
+Currency control, which should prevent a race condition by not allowing any threat, entering a political
+
+131
+00:10:09,000 --> 00:10:15,000
+section, if some as a threat currently executing the court of critical section somewhere, you married
+
+132
+00:10:15,000 --> 00:10:23,000
+another definition saying that monitor is a threat, safe class object or module that is partially also
+
+133
+00:10:23,000 --> 00:10:24,000
+makes sense.
+
+134
+00:10:24,000 --> 00:10:31,000
+We can use an object as a flag and as a monitor to indicate which threat captures and monitor of the
+
+135
+00:10:31,000 --> 00:10:34,000
+object and which threat released monitor of the object.
+
+136
+00:10:35,000 --> 00:10:39,000
+So injera monitor is implicitly associated with an object.
+
+137
+00:10:39,000 --> 00:10:42,000
+Let me support my explanation, which was analyzation.
+
+138
+00:10:43,000 --> 00:10:45,000
+Let's look at the example with my car.
+
+139
+00:10:45,000 --> 00:10:52,000
+Here is my only Rs5 that can reach 60 miles per hour in less than a three point five seconds.
+
+140
+00:10:52,000 --> 00:10:55,000
+This has nothing in common with multiscreen and yet.
+
+141
+00:10:55,000 --> 00:10:56,000
+But we will jump to the details.
+
+142
+00:10:56,000 --> 00:11:01,000
+So imagine that this car is a monitor and critical sections.
+
+143
+00:11:01,000 --> 00:11:06,000
+Here are accelerator pedal, brake pedal, steering wheel and so on.
+
+144
+00:11:07,000 --> 00:11:08,000
+I'm a threat.
+
+145
+00:11:09,000 --> 00:11:12,000
+And girlfriend of mine is another threat of execution.
+
+146
+00:11:13,000 --> 00:11:16,000
+Those threats can't simultaneously interact with.
+
+147
+00:11:17,000 --> 00:11:22,000
+It will be horrible sink in case me and your friend of mine will be pushing on different pedals simultaneously.
+
+148
+00:11:23,000 --> 00:11:27,000
+I can capture, monitor and do operations with the cars that they need.
+
+149
+00:11:28,000 --> 00:11:30,000
+I open the car and drive to an office.
+
+150
+00:11:30,000 --> 00:11:33,000
+And when I got back home, I released the monitor.
+
+151
+00:11:34,000 --> 00:11:40,000
+When the monitor is released and a threat, my girlfriend can take it and can go to the beauty salon,
+
+152
+00:11:40,000 --> 00:11:41,000
+for example.
+
+153
+00:11:41,000 --> 00:11:49,000
+Is it clear so far there are also some methods that allow to interact with, monitor their weight,
+
+154
+00:11:49,000 --> 00:11:51,000
+notify and notify all.
+
+155
+00:11:51,000 --> 00:11:52,000
+Wait.
+
+156
+00:11:52,000 --> 00:11:59,000
+MassArt is overloaded and has versions with arguments that time related arguments milliseconds and nanoseconds
+
+157
+00:12:00,000 --> 00:12:09,000
+zest masses inherited in all types from object class because all objects in Java implicitly extant object
+
+158
+00:12:09,000 --> 00:12:09,000
+class.
+
+159
+00:12:10,000 --> 00:12:11,000
+What these methods do.
+
+160
+00:12:12,000 --> 00:12:13,000
+Let's review an example.
+
+161
+00:12:14,000 --> 00:12:21,000
+Imagine that my girlfriend took a car and all of a sudden something happened with a car and it was stopped
+
+162
+00:12:21,000 --> 00:12:21,000
+unexpectedly.
+
+163
+00:12:22,000 --> 00:12:26,000
+She called me and asked me to pick up her with the car and help.
+
+164
+00:12:26,000 --> 00:12:32,000
+When I found her in the city, she went out of the car and let me in what she did.
+
+165
+00:12:32,000 --> 00:12:37,000
+She released more nature of the object temporarily and let me capture monitor.
+
+166
+00:12:38,000 --> 00:12:44,000
+She still has intention to drive further, but she just let me also perform some actions with the car.
+
+167
+00:12:44,000 --> 00:12:46,000
+And that is exactly what the weight method does.
+
+168
+00:12:46,000 --> 00:12:51,000
+It's just really this monitor and let us the capture monitor.
+
+169
+00:12:51,000 --> 00:12:57,000
+I was happy to discover that my girlfriend just didn't activate Immobiliser and the engine appeared
+
+170
+00:12:57,000 --> 00:12:58,000
+to be blocked.
+
+171
+00:12:58,000 --> 00:13:03,000
+I think that and told her that she can drive from wherever she needs.
+
+172
+00:13:03,000 --> 00:13:11,000
+What I did, I called notify Masset on the monitor, notify Masset makes all threats that we're waiting
+
+173
+00:13:11,000 --> 00:13:14,000
+are aware that they can proceed their work.
+
+174
+00:13:14,000 --> 00:13:21,000
+That means we use with Massata to let other threats perform some actions and modify the state of some
+
+175
+00:13:21,000 --> 00:13:24,000
+objects if needed, of some shared resources.
+
+176
+00:13:24,000 --> 00:13:31,000
+And after that, other threats should call notify Masset to update all threats that they've done.
+
+177
+00:13:32,000 --> 00:13:34,000
+Another example of wait and notify.
+
+178
+00:13:35,000 --> 00:13:39,000
+You're going to have coding exercises soon and there will be a task about readers and writers.
+
+179
+00:13:39,000 --> 00:13:46,000
+For example, readers interact with some buffer of memory where readers should find information to read
+
+180
+00:13:47,000 --> 00:13:52,000
+readers captions and monitor of buffer object and doesn't allow anyone to work with it.
+
+181
+00:13:53,000 --> 00:13:59,000
+Once readers read all information from Buffer and Buffer is empty, they're turned into the waiting
+
+182
+00:13:59,000 --> 00:14:04,000
+state and they wait until right to put your information into the buffer.
+
+183
+00:14:05,000 --> 00:14:11,000
+Once the writer finished its job and put all information and buffer it, notifies our readers that we're
+
+184
+00:14:11,000 --> 00:14:16,000
+in a weakened state by and notify all Masset on buffer object.
+
+185
+00:14:16,000 --> 00:14:20,000
+And now readers continue with information from Buffer and so on.
+
+186
+00:14:20,000 --> 00:14:27,000
+Notify all is a matter to notify not only once residents in waiting queue, but notify us all threats
+
+187
+00:14:27,000 --> 00:14:28,000
+that time in the waiting queue.
+
+188
+00:14:29,000 --> 00:14:33,000
+Hope that now you understood what is and wanted to know.
+
+189
+00:14:33,000 --> 00:14:38,000
+Let's understand the difference between two terms monitor and mutex.
+
+190
+00:14:38,000 --> 00:14:44,000
+Conceptually, these two terms are similar zooni difference is how they are implemented inside.
+
+191
+00:14:45,000 --> 00:14:52,000
+Usually the implementation of monitors is faster light weight since it is designed for multiple threaded
+
+192
+00:14:52,000 --> 00:14:54,000
+synchronization within the same process.
+
+193
+00:14:55,000 --> 00:15:01,000
+Also, usually it is provided by a framework library itself and not request the operating system.
+
+194
+00:15:01,000 --> 00:15:05,000
+Usually matrixes are provided by the operating system.
+
+195
+00:15:05,000 --> 00:15:12,000
+Kernell what is always Curnoe in simple words, it is a computer program at the core of the computer's
+
+196
+00:15:12,000 --> 00:15:16,000
+operating system and has complete control over everything in the system.
+
+197
+00:15:17,000 --> 00:15:21,000
+It also handles data processing instructions for the central processing unit.
+
+198
+00:15:22,000 --> 00:15:27,000
+It is a portion of the operating system code that is always resident in memory.
+
+199
+00:15:28,000 --> 00:15:33,000
+Usually libraries frameworks simply provide an interface to invoke mutex.
+
+200
+00:15:33,000 --> 00:15:40,000
+This makes them heavy weight slower, but allows us to achieve expected to result to synchronize threads
+
+201
+00:15:40,000 --> 00:15:42,000
+between each other and lock on.
+
+202
+00:15:42,000 --> 00:15:49,000
+Mutex from neutral exclusion is a mechanism that enforces limits on access to resource.
+
+203
+00:15:49,000 --> 00:15:55,000
+When there are many threats of execution, a lock is designed to enforce a mutual exclusion.
+
+204
+00:15:55,000 --> 00:16:01,000
+Concurrency Control Policy and Monitor consists of a mutex lock object and condition variables.
+
+205
+00:16:01,000 --> 00:16:07,000
+A condition variable essentially is a container of threats that are waiting for a certain condition
+
+206
+00:16:08,000 --> 00:16:08,000
+more.
+
+207
+00:16:08,000 --> 00:16:14,000
+Charters provide a mechanism for threats to temporarily give up exclusive access in order to wait for
+
+208
+00:16:14,000 --> 00:16:19,000
+some conditions to be met before gaining exclusive access and resuming their task.
+
+209
+00:16:20,000 --> 00:16:26,000
+So monitor is different than mutex, but they can be considered similar in the sense that the monitor
+
+210
+00:16:26,000 --> 00:16:31,000
+is built on top of mutex in this lesson we'll use to monitor transfers.
+
+211
+00:16:31,000 --> 00:16:36,000
+But just in case you heard that somebody uses mutex term, you'll really know the difference.
+
+212
+00:16:37,000 --> 00:16:43,000
+Now, let's look at the Korean example and we'll try to understand how monitor works, how synchronization
+
+213
+00:16:43,000 --> 00:16:47,000
+happens and practice example, a way to notify interaction.
+
+214
+00:16:47,000 --> 00:16:51,000
+Let's get back to synchronized examples that we already saw today.
+
+215
+00:16:51,000 --> 00:16:54,000
+There is one more method here that is similar to synchronized one.
+
+216
+00:16:55,000 --> 00:17:00,000
+Pay attention that this method doesn't have synchronized keywords in the same line was messed name,
+
+217
+00:17:00,000 --> 00:17:02,000
+but it contains synchronized block.
+
+218
+00:17:03,000 --> 00:17:03,000
+What is this?
+
+219
+00:17:04,000 --> 00:17:09,000
+So when you have synchronized Masad, it is fair to say that you captured the monitor of this object
+
+220
+00:17:10,000 --> 00:17:12,000
+of object which he used to Vogues and mastered.
+
+221
+00:17:13,000 --> 00:17:19,000
+But what object you used to walk in Inmarsat in this case and also how it works with static methods,
+
+222
+00:17:19,000 --> 00:17:21,000
+with static methods.
+
+223
+00:17:21,000 --> 00:17:25,000
+You capture Moneta of this class to create synchronized block.
+
+224
+00:17:25,000 --> 00:17:31,000
+You have to pass the reference to an object where you want to capture monitor right now.
+
+225
+00:17:31,000 --> 00:17:33,000
+And this block may enter only once read.
+
+226
+00:17:33,000 --> 00:17:40,000
+And once the threat will leave this block, it will release monitor of this class and the next threat
+
+227
+00:17:40,000 --> 00:17:45,000
+will enter this block and will capture monitor, of course, with synchronized methods.
+
+228
+00:17:45,000 --> 00:17:51,000
+That principle is the same, but you just have synchronized access to the whole method, and not only
+
+229
+00:17:51,000 --> 00:17:56,000
+for a specific part of it, why you might want to use synchronize blocks.
+
+230
+00:17:56,000 --> 00:18:02,000
+So this part of the spreading optimization, because it may be that actually not aligned in your methods
+
+231
+00:18:02,000 --> 00:18:04,000
+is a critical section.
+
+232
+00:18:04,000 --> 00:18:09,000
+Probably there are some operations that have multiple threads may perform in parallel.
+
+233
+00:18:09,000 --> 00:18:11,000
+That might be really different cases.
+
+234
+00:18:11,000 --> 00:18:16,000
+For example, here you will print some text to console or you just want to log that.
+
+235
+00:18:16,000 --> 00:18:22,000
+You enter this method and you want to log some message after critical section, or it can be some preparation
+
+236
+00:18:22,000 --> 00:18:24,000
+activities before the duration.
+
+237
+00:18:24,000 --> 00:18:27,000
+Anyway, log in print and text.
+
+238
+00:18:27,000 --> 00:18:30,000
+The console in this case is not a critical section.
+
+239
+00:18:30,000 --> 00:18:34,000
+This will not bring you to inconsistent state of your system.
+
+240
+00:18:34,000 --> 00:18:41,000
+That's why there is no need to make your threats, wait to do operations that they can do now without
+
+241
+00:18:41,000 --> 00:18:42,000
+waiting.
+
+242
+00:18:42,000 --> 00:18:47,000
+So all core outside of the synchronized block may be executed concurrently.
+
+243
+00:18:48,000 --> 00:18:54,000
+When you will create a certain program, always ask yourself, do I need to synchronize access to this
+
+244
+00:18:54,000 --> 00:19:00,000
+chunk of code or know what will happen if the threat will execute this code simultaneously?
+
+245
+00:19:00,000 --> 00:19:06,000
+And in case you discover that nothing bad would happen, do not with this code in synchronized lock,
+
+246
+00:19:07,000 --> 00:19:12,000
+because in this case you would improve performance of your app by not making your sweats.
+
+247
+00:19:12,000 --> 00:19:12,000
+Wait.
+
+248
+00:19:12,000 --> 00:19:19,000
+And when they shouldn't be waiting in general, this is rule of thumb to have a small synchronized block
+
+249
+00:19:19,000 --> 00:19:19,000
+as possible.
+
+250
+00:19:20,000 --> 00:19:25,000
+In case this method won't be static, you will capture monitor of another object.
+
+251
+00:19:25,000 --> 00:19:32,000
+In this case, you would capture monitor of this object, the one that invokes this method.
+
+252
+00:19:32,000 --> 00:19:34,000
+So these two methods now are similar.
+
+253
+00:19:35,000 --> 00:19:40,000
+What potential drawback you see in using synchronize locks with synchronized locks?
+
+254
+00:19:40,000 --> 00:19:45,000
+You can't capture a monitor in one place and release it completely in another place.
+
+255
+00:19:46,000 --> 00:19:52,000
+You can't describe synchronized lock in multiple methods, but there is so called a lock API that we
+
+256
+00:19:52,000 --> 00:19:54,000
+are going to learn all kinds.
+
+257
+00:19:54,000 --> 00:19:59,000
+Of course, that will allow you to capture more data in one place and release it somewhere else.
+
+258
+00:20:00,000 --> 00:20:06,000
+Now let's look at WAF not for example, I grouped all the classes related to this example in a separate
+
+259
+00:20:06,000 --> 00:20:06,000
+package.
+
+260
+00:20:06,000 --> 00:20:08,000
+Here was name with Latifi.
+
+261
+00:20:09,000 --> 00:20:14,000
+Let me open them a file and will start from one could imagine that I have some message.
+
+262
+00:20:14,000 --> 00:20:19,000
+I create object of this type and left some message to process it.
+
+263
+00:20:19,000 --> 00:20:25,000
+Let's have a look at the source code of message type message has one properties and describes its state.
+
+264
+00:20:26,000 --> 00:20:32,000
+It is called message and need this type fostering position because he already knows that string itself
+
+265
+00:20:32,000 --> 00:20:34,000
+immutable object.
+
+266
+00:20:34,000 --> 00:20:36,000
+Once a great object of type string.
+
+267
+00:20:36,000 --> 00:20:38,000
+I can't change it state.
+
+268
+00:20:39,000 --> 00:20:46,000
+That's why I created separate type that has API that allows me to update the state of the same object.
+
+269
+00:20:46,000 --> 00:20:48,000
+Also, there are two matters here.
+
+270
+00:20:48,000 --> 00:20:49,000
+Getter and setter.
+
+271
+00:20:50,000 --> 00:20:50,000
+That's it.
+
+272
+00:20:51,000 --> 00:20:52,000
+Let's get back to the demo file.
+
+273
+00:20:53,000 --> 00:20:56,000
+The second object that I create here is a reader object.
+
+274
+00:20:56,000 --> 00:20:58,000
+I pass a reference to the message object.
+
+275
+00:20:58,000 --> 00:20:59,000
+We are constructor.
+
+276
+00:21:00,000 --> 00:21:06,000
+After that I create a threat object based reference to the readers and name as threat as reader one
+
+277
+00:21:06,000 --> 00:21:07,000
+and start the threat.
+
+278
+00:21:08,000 --> 00:21:14,000
+Probably already understands its rather implements Runnable interface, and you're right where you source
+
+279
+00:21:14,000 --> 00:21:16,000
+code of reading type in a few seconds.
+
+280
+00:21:17,000 --> 00:21:19,000
+Also another reader and pay attention.
+
+281
+00:21:20,000 --> 00:21:22,000
+I pass the same message, object to the constructor.
+
+282
+00:21:23,000 --> 00:21:26,000
+This would be exactly the object that I would use for multiple threads.
+
+283
+00:21:26,000 --> 00:21:32,000
+Synchronization here I create another thread, object to his name reader to and run this thread.
+
+284
+00:21:33,000 --> 00:21:39,000
+So after this line we would have three threads running my main threat and to readers threats.
+
+285
+00:21:40,000 --> 00:21:44,000
+Let's learn what will be executed inside our readers around method.
+
+286
+00:21:45,000 --> 00:21:49,000
+As you can see, reader class implements Runnable Interface.
+
+287
+00:21:49,000 --> 00:21:50,000
+It has one property.
+
+288
+00:21:51,000 --> 00:21:58,000
+This is property of message type inside the one massive yet name of the thread for our demo purposes
+
+289
+00:21:58,000 --> 00:21:59,000
+to print its name to consult.
+
+290
+00:22:00,000 --> 00:22:02,000
+And after that I have synchronized S..
+
+291
+00:22:03,000 --> 00:22:09,000
+I didn't make synchronized maps because in this case all reader objects would have separate monitor
+
+292
+00:22:10,000 --> 00:22:11,000
+and need common monitoring.
+
+293
+00:22:11,000 --> 00:22:13,000
+There's a shared between two threats.
+
+294
+00:22:14,000 --> 00:22:20,000
+This is additional advantage of synchronized block because you can pass any object as a reference to
+
+295
+00:22:20,000 --> 00:22:21,000
+capture monitor.
+
+296
+00:22:22,000 --> 00:22:26,000
+And I have this massive object that is shared between two waiters.
+
+297
+00:22:26,000 --> 00:22:29,000
+So I kept your monitor off message object.
+
+298
+00:22:29,000 --> 00:22:37,000
+After that, I claim to cancel and indicate that this threat is waiting to be notified and Prince Current
+
+299
+00:22:37,000 --> 00:22:41,000
+milliseconds after that I go wait Masad on my message object.
+
+300
+00:22:41,000 --> 00:22:47,000
+One more important thing you can call way Massud only in specific context.
+
+301
+00:22:47,000 --> 00:22:53,000
+You can call this method only from synchronized sections and from synchronized methods in case you would
+
+302
+00:22:53,000 --> 00:22:54,000
+invoke weight.
+
+303
+00:22:54,000 --> 00:23:00,000
+Massive note in synchronized context, you will get runtime exception with name, illegal and interstate
+
+304
+00:23:00,000 --> 00:23:04,000
+exception because Red is not an owner of a monitor.
+
+305
+00:23:05,000 --> 00:23:11,000
+Once I call Weight Masset, this thread is in the waiting queue to proceed execution when it will be
+
+306
+00:23:11,000 --> 00:23:12,000
+notified.
+
+307
+00:23:12,000 --> 00:23:16,000
+At the same time, the second reader managed to enter this section.
+
+308
+00:23:16,000 --> 00:23:23,000
+Considering the first reader called Wait Masset on monitor, that means that the monitor is not blocked
+
+309
+00:23:23,000 --> 00:23:26,000
+and another reader can enter the section.
+
+310
+00:23:26,000 --> 00:23:29,000
+Now it is time to learn what is happening next.
+
+311
+00:23:29,000 --> 00:23:31,000
+Let's get back to our demo file.
+
+312
+00:23:31,000 --> 00:23:34,000
+Now it's time to create a notifier object.
+
+313
+00:23:34,000 --> 00:23:39,000
+Notifier type is my custom type that I also described in this package.
+
+314
+00:23:39,000 --> 00:23:43,000
+Pay attention that I pass the reference to the same message object.
+
+315
+00:23:43,000 --> 00:23:44,000
+Great.
+
+316
+00:23:44,000 --> 00:23:48,000
+A threat was named Notifier and started after that.
+
+317
+00:23:48,000 --> 00:23:49,000
+I printed all threads I started.
+
+318
+00:23:50,000 --> 00:23:52,000
+Let's investigate what this notified do.
+
+319
+00:23:52,000 --> 00:23:58,000
+As you can see, objects of this type also will store as a reference to the message object.
+
+320
+00:23:58,000 --> 00:23:59,000
+This is our monitor.
+
+321
+00:24:00,000 --> 00:24:07,000
+In one method we get the name of the threat and indicate that this threat started its work after Z,
+
+322
+00:24:07,000 --> 00:24:10,000
+I made this threat sleep for one hundred milliseconds.
+
+323
+00:24:10,000 --> 00:24:14,000
+This is to ensure that the reader objects captured monitor first.
+
+324
+00:24:14,000 --> 00:24:22,000
+Once the threat wakes up, I try to enter, synchronize the book and undo any other threat is captured
+
+325
+00:24:22,000 --> 00:24:23,000
+in message monitor.
+
+326
+00:24:23,000 --> 00:24:30,000
+All other threats, including this one will stay right before the critical section and would not enter
+
+327
+00:24:30,000 --> 00:24:34,000
+it until get notified from the threats that the monitor is released.
+
+328
+00:24:34,000 --> 00:24:37,000
+You remember that in other threats we invoked.
+
+329
+00:24:37,000 --> 00:24:38,000
+Wait Massett.
+
+330
+00:24:38,000 --> 00:24:43,000
+That means that Notifier may enter this section and capture Monisha.
+
+331
+00:24:43,000 --> 00:24:45,000
+In this critical section.
+
+332
+00:24:45,000 --> 00:24:47,000
+We perform message processing.
+
+333
+00:24:47,000 --> 00:24:51,000
+We change the text to indicate which Notifier updated the message.
+
+334
+00:24:51,000 --> 00:24:59,000
+And after that I invoke is to notify or notify all assets in case I would invoke notify massive on the
+
+335
+00:24:59,000 --> 00:25:01,000
+one threat will be notified.
+
+336
+00:25:01,000 --> 00:25:03,000
+Is a reader one or reader.
+
+337
+00:25:03,000 --> 00:25:04,000
+So let's check this.
+
+338
+00:25:05,000 --> 00:25:06,000
+I run them a file.
+
+339
+00:25:06,000 --> 00:25:11,000
+Here is a notification about we do once read started notify us.
+
+340
+00:25:11,000 --> 00:25:16,000
+Threats started here and we are to start started and waiting to get notified here at this time.
+
+341
+00:25:17,000 --> 00:25:22,000
+And once I called notify MassArt reader finished its execution.
+
+342
+00:25:22,000 --> 00:25:27,000
+So now you can see that we do one, get notified and read other one message.
+
+343
+00:25:27,000 --> 00:25:30,000
+Protest in the source code of reader class.
+
+344
+00:25:30,000 --> 00:25:36,000
+You can see that I print this text to console after wait Macit at the end of round method.
+
+345
+00:25:36,000 --> 00:25:39,000
+So often defecation all code that is below.
+
+346
+00:25:39,000 --> 00:25:41,000
+Wait Massata got executed.
+
+347
+00:25:41,000 --> 00:25:44,000
+Pay attention that our game isn't stopped yet.
+
+348
+00:25:44,000 --> 00:25:50,000
+You can see this red stop sign that tells us that I can stop game but it is run.
+
+349
+00:25:50,000 --> 00:25:53,000
+But why another idle threat is working now.
+
+350
+00:25:54,000 --> 00:25:56,000
+It actually does nothing at the moment.
+
+351
+00:25:56,000 --> 00:25:59,000
+It is just waiting to be notified in this line.
+
+352
+00:26:00,000 --> 00:26:05,000
+But only we know that there are no threats left in the app right now that would be able to notify us
+
+353
+00:26:05,000 --> 00:26:08,000
+with their object all as a threat.
+
+354
+00:26:08,000 --> 00:26:15,000
+I mean, the main threat with the one threat notifier already executed and finished, and this is the
+
+355
+00:26:15,000 --> 00:26:17,000
+last threat that is waiting right now.
+
+356
+00:26:17,000 --> 00:26:24,000
+Let me stop again if you know that such case may happen, in case you know that two more threats might
+
+357
+00:26:24,000 --> 00:26:30,000
+enter a critical section and wait until being notified, you should think about your multiscreen logic
+
+358
+00:26:30,000 --> 00:26:32,000
+very carefully to avoid cases like this.
+
+359
+00:26:33,000 --> 00:26:37,000
+One thread is waiting as low as a threat, always a threat.
+
+360
+00:26:37,000 --> 00:26:38,000
+How to figure this?
+
+361
+00:26:39,000 --> 00:26:45,000
+You should control how many times you call Wakamatsu and how many times you call notify Mass.
+
+362
+00:26:46,000 --> 00:26:53,000
+Considering we have one point in our app where we call notify MassArt in our single Notify Threat and
+
+363
+00:26:53,000 --> 00:26:55,000
+we have to either objects where we call with Macit.
+
+364
+00:26:56,000 --> 00:27:03,000
+Let's invoke notify all Massett in our notify I open, notify a class and will invoke notify all Masset
+
+365
+00:27:03,000 --> 00:27:05,000
+instead simply notify Mass.
+
+366
+00:27:06,000 --> 00:27:07,000
+Let's run our F one more time.
+
+367
+00:27:08,000 --> 00:27:13,000
+Now you can see that all threats finished their work and no other threats running.
+
+368
+00:27:14,000 --> 00:27:15,000
+We have both.
+
+369
+00:27:15,000 --> 00:27:17,000
+Neither one and we are to notify.
+
+370
+00:27:17,000 --> 00:27:22,000
+You can verify this when instigation of console output is clear.
+
+371
+00:27:22,000 --> 00:27:28,000
+It is great that now you know how to work with notified masses and synchronization basics.
+
+372
+00:27:28,000 --> 00:27:31,000
+Let's recap what we have learned in this lesson.
+
+373
+00:27:31,000 --> 00:27:34,000
+In this lesson we learned what critical section is.
+
+374
+00:27:35,000 --> 00:27:38,000
+You understood what atomic and atomic operations are.
+
+375
+00:27:39,000 --> 00:27:41,000
+And we are still going to learn with you.
+
+376
+00:27:41,000 --> 00:27:45,000
+Jabiri two concurrent atomic package in the next lessons.
+
+377
+00:27:45,000 --> 00:27:46,000
+So stay tuned.
+
+378
+00:27:47,000 --> 00:27:51,000
+Now, you know what monitor and mutex are and what is the difference between them?
+
+379
+00:27:51,000 --> 00:27:56,000
+Also, you know what a synchronized method and what a synchronized block.
+
+380
+00:27:56,000 --> 00:28:01,000
+And at the end of the lesson, we have learned what weight notify and notify all methods are.
+
+381
+00:28:02,000 --> 00:28:05,000
+That's all for today, hope you enjoyed this lesson.
+
+382
+00:28:06,000 --> 00:28:07,000
+Thank you for your attention.
+
+383
+00:28:07,000 --> 00:28:09,000
+See you in the next lesson.
+
diff --git a/27 - Multithreading/005 AtomicInteger-demo-source-code.url b/27 - Multithreading/005 AtomicInteger-demo-source-code.url
new file mode 100644
index 0000000000000000000000000000000000000000..88f94098a3ab17c36e200ad6a91dd7a56f4c4cd3
--- /dev/null
+++ b/27 - Multithreading/005 AtomicInteger-demo-source-code.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/atomictypes/AtomicIntegerDemo.java
\ No newline at end of file
diff --git a/27 - Multithreading/005 InheritablThreadLocal-demo-source-code.url b/27 - Multithreading/005 InheritablThreadLocal-demo-source-code.url
new file mode 100644
index 0000000000000000000000000000000000000000..5541a5fc19020692d60832c61e3723205603ea5b
--- /dev/null
+++ b/27 - Multithreading/005 InheritablThreadLocal-demo-source-code.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/InheritableThreadLocalDemo.java
\ No newline at end of file
diff --git a/27 - Multithreading/005 Memory Management in Multithreading Programs_en.srt b/27 - Multithreading/005 Memory Management in Multithreading Programs_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..14e257e5ea31a82e8b01366f02a51a31bc60f942
--- /dev/null
+++ b/27 - Multithreading/005 Memory Management in Multithreading Programs_en.srt
@@ -0,0 +1,1132 @@
+1
+00:00:05,000 --> 00:00:11,000
+Hello, today, we're going to have interesting lesson, you know, sometimes it happens and the topics
+
+2
+00:00:11,000 --> 00:00:17,000
+that I need to explain it, but they're either too small for a separate lesson or highly connected with
+
+3
+00:00:17,000 --> 00:00:17,000
+other topics.
+
+4
+00:00:18,000 --> 00:00:22,000
+That's why a group such topics and decided to put them in one lesson.
+
+5
+00:00:22,000 --> 00:00:27,000
+We'll start from understanding of memory management in Java and just writing programs.
+
+6
+00:00:27,000 --> 00:00:32,000
+This will give you information about how data is managed by different threats.
+
+7
+00:00:32,000 --> 00:00:36,000
+It is also important to understand hardware, memory, architecture.
+
+8
+00:00:36,000 --> 00:00:42,000
+It is a different from general memory model, but your memory model works with hardware memory and is
+
+9
+00:00:42,000 --> 00:00:43,000
+built on top of it.
+
+10
+00:00:44,000 --> 00:00:50,000
+That's why software engineers, we need to understand how all this is connected, learns this information.
+
+11
+00:00:50,000 --> 00:00:56,000
+It will be easier for you to understand volatile keywords and how it works in various lessons.
+
+12
+00:00:56,000 --> 00:01:01,000
+We already talked about atomic operations and I mentioned that there are generally two concurrent atomic
+
+13
+00:01:01,000 --> 00:01:05,000
+package that contains types that supports atomic operations.
+
+14
+00:01:05,000 --> 00:01:11,000
+In this letter, we'll review this package at the end of the and will want to read local variables are.
+
+15
+00:01:12,000 --> 00:01:17,000
+I will also share with you some use cases when you might need to use read local, but it will be up
+
+16
+00:01:17,000 --> 00:01:22,000
+to you how to use this to also talk about inheritable local.
+
+17
+00:01:22,000 --> 00:01:24,000
+And I will show you examples.
+
+18
+00:01:24,000 --> 00:01:25,000
+Let's start.
+
+19
+00:01:25,000 --> 00:01:31,000
+And before we start learning to read local, volatile and other concepts, let's understand first memory
+
+20
+00:01:31,000 --> 00:01:37,000
+management and how Seurat's use in memory, why it is important for us, because we need to know and
+
+21
+00:01:37,000 --> 00:01:43,000
+understand when different threads can use values, return to shared variables by Osas threats and how
+
+22
+00:01:43,000 --> 00:01:46,000
+to synchronize access to shared variables when necessary.
+
+23
+00:01:46,000 --> 00:01:52,000
+When I have multiple threats, Dunam divides memories between stress tests and the hit their separate
+
+24
+00:01:52,000 --> 00:01:53,000
+stack for each threat.
+
+25
+00:01:53,000 --> 00:01:55,000
+And you can see the visualizations a slide.
+
+26
+00:01:55,000 --> 00:01:57,000
+What is stored in threat stack?
+
+27
+00:01:58,000 --> 00:02:03,000
+If you remember less lesson about a memory module from my Java course, you might guess what is stored
+
+28
+00:02:03,000 --> 00:02:09,000
+in old stack of each threat is information about mass that we invoke from the threat or local variables
+
+29
+00:02:09,000 --> 00:02:11,000
+for each must have been executed.
+
+30
+00:02:12,000 --> 00:02:16,000
+Local variables created in the threat obviously are not visible to all of us.
+
+31
+00:02:16,000 --> 00:02:22,000
+Let's hope you remember that if memory stores, objects, objects are instances of all reference types
+
+32
+00:02:22,000 --> 00:02:23,000
+that we know.
+
+33
+00:02:23,000 --> 00:02:29,000
+And it doesn't matter if an object was created as a threat and assigned to a local variable, or even
+
+34
+00:02:29,000 --> 00:02:35,000
+if it is created as a member variable of another object, the object is still stored in the hip, but
+
+35
+00:02:35,000 --> 00:02:39,000
+the references to these objects are stored in threads stack.
+
+36
+00:02:40,000 --> 00:02:43,000
+Let's look at more detailed version of previous life here.
+
+37
+00:02:43,000 --> 00:02:48,000
+You can see where information about local variables and objects is stored.
+
+38
+00:02:48,000 --> 00:02:49,000
+So nothing new to you.
+
+39
+00:02:49,000 --> 00:02:52,000
+In case you are familiar with Java memory module.
+
+40
+00:02:52,000 --> 00:02:58,000
+Also important thing to highlight here that the variable may be of primitive and reference type variable
+
+41
+00:02:58,000 --> 00:03:05,000
+of primitive type contains value in itself and completely stored in threat stack in case variable has
+
+42
+00:03:05,000 --> 00:03:06,000
+reference time.
+
+43
+00:03:06,000 --> 00:03:13,000
+In this case, a reference to the heap is stored in stack memory and object is stored in the memory.
+
+44
+00:03:13,000 --> 00:03:15,000
+What about static variables?
+
+45
+00:03:15,000 --> 00:03:20,000
+Take into account static variables don't belong to any object, but belong to class itself.
+
+46
+00:03:21,000 --> 00:03:24,000
+They are stored in the memory along with the class definition.
+
+47
+00:03:25,000 --> 00:03:31,000
+Since Case Thread has a reference to an object, it can access object in memory using the reference
+
+48
+00:03:31,000 --> 00:03:35,000
+and each side may do this in case it knows is a reference to an object.
+
+49
+00:03:36,000 --> 00:03:38,000
+And now let me share a really interesting scene.
+
+50
+00:03:39,000 --> 00:03:43,000
+Imagine that this column masset on the same object at the same moment of time.
+
+51
+00:03:44,000 --> 00:03:48,000
+These threats, both of them will access objects, variables.
+
+52
+00:03:48,000 --> 00:03:53,000
+But we have just learned the local variables are stored in a stack of each threat.
+
+53
+00:03:53,000 --> 00:04:00,000
+So each threat will have its own reference to the object in the Heat and its own copy of the local variable
+
+54
+00:04:01,000 --> 00:04:05,000
+that is important for understanding, for data manipulation from different threats.
+
+55
+00:04:05,000 --> 00:04:12,000
+So in this case, some local variables are completely copied to each threat, and each threat has copy
+
+56
+00:04:12,000 --> 00:04:14,000
+of the reference to an object in memory.
+
+57
+00:04:15,000 --> 00:04:18,000
+Now let's talk about hardware, memory architecture.
+
+58
+00:04:18,000 --> 00:04:24,000
+As I already mentioned in the agenda of this lesson, it is important for us to understand how hardware
+
+59
+00:04:24,000 --> 00:04:28,000
+memory is architected because general memory model is built on top of it.
+
+60
+00:04:29,000 --> 00:04:33,000
+So another computer often has to and even more in central processing units.
+
+61
+00:04:34,000 --> 00:04:36,000
+That is why they're called CPU.
+
+62
+00:04:37,000 --> 00:04:38,000
+What does this mean for us?
+
+63
+00:04:38,000 --> 00:04:46,000
+That means that we can physically has calculations done in parallel because you can run the one thread
+
+64
+00:04:46,000 --> 00:04:47,000
+at any given time.
+
+65
+00:04:48,000 --> 00:04:54,000
+C.P.U contains a set of registers zis registers consider to be memory of our CPU.
+
+66
+00:04:54,000 --> 00:05:01,000
+That's why you can perform operations on these registers much faster, that it can perform on variables
+
+67
+00:05:01,000 --> 00:05:02,000
+in the main memory.
+
+68
+00:05:02,000 --> 00:05:07,000
+Besides registers, CPU also have Sibiu cash memory.
+
+69
+00:05:07,000 --> 00:05:13,000
+And again, if we were talking about performance, it's worth to say that C.P.U is able to access cash
+
+70
+00:05:13,000 --> 00:05:20,000
+memory much faster than the RAM memory, but obviously not as fast as it can access internal registers.
+
+71
+00:05:21,000 --> 00:05:24,000
+ROMME stands for random access memory.
+
+72
+00:05:24,000 --> 00:05:31,000
+It is a form of computer memory that can be read and changed in any order typically used to store data.
+
+73
+00:05:32,000 --> 00:05:37,000
+For example, you start from some room is reserved for Google.
+
+74
+00:05:37,000 --> 00:05:42,000
+You start your Java app JVM reserves from memory for the Java process.
+
+75
+00:05:43,000 --> 00:05:50,000
+LCP use may access around and the RAM is typically much bigger than the cache memory of the CPU's.
+
+76
+00:05:50,000 --> 00:05:54,000
+Let's understand how the process of reading and writing data is happening.
+
+77
+00:05:54,000 --> 00:06:00,000
+In case you need to read some data from RAM, it will read some parts of the data from RAM into the
+
+78
+00:06:00,000 --> 00:06:07,000
+CPU cache and it is also possible the CPU will read some parts of the data into internal registers and
+
+79
+00:06:07,000 --> 00:06:10,000
+only after that operate on that data.
+
+80
+00:06:10,000 --> 00:06:13,000
+And in case you need to write, result back to RAM.
+
+81
+00:06:14,000 --> 00:06:17,000
+We are going through the same route, but just in other direction.
+
+82
+00:06:18,000 --> 00:06:25,000
+From CPU registers to RAM, CPU will flush the result of computation from its internal register.
+
+83
+00:06:25,000 --> 00:06:32,000
+Those are cache memory and at some point the value back to the RAM eviction policy from CPU cash is
+
+84
+00:06:32,000 --> 00:06:33,000
+simple.
+
+85
+00:06:33,000 --> 00:06:38,000
+One memory is needed for something else, then cache memory is flashed back to zero.
+
+86
+00:06:39,000 --> 00:06:45,000
+So as you can see, Java memory model and hardware memory architecture are not the same sync.
+
+87
+00:06:45,000 --> 00:06:52,000
+There is no separation between stack and heap in hardware memory, but how it is connected.
+
+88
+00:06:52,000 --> 00:07:00,000
+Then let me show on the next slide both stack and the heap memory allocated in ram memory that is reserved
+
+89
+00:07:00,000 --> 00:07:08,000
+for Java process parts of threats stacks and he may sometimes be present in CPU caches and in internal
+
+90
+00:07:08,000 --> 00:07:09,000
+SEPI registers.
+
+91
+00:07:09,000 --> 00:07:16,000
+What problem may occur in case objects and variables are stored in different memory areas in the computer?
+
+92
+00:07:17,000 --> 00:07:18,000
+The domain potential problems.
+
+93
+00:07:19,000 --> 00:07:25,000
+There was a batch of threat updates and the second problem is there is a condition during the reading,
+
+94
+00:07:25,000 --> 00:07:27,000
+checking and writing shared variables.
+
+95
+00:07:28,000 --> 00:07:31,000
+Let me explain what these issues are about and details.
+
+96
+00:07:32,000 --> 00:07:34,000
+The first issue is visibility of threat updates.
+
+97
+00:07:35,000 --> 00:07:38,000
+Imagine that some updated copy of the variable.
+
+98
+00:07:38,000 --> 00:07:45,000
+There is no guarantees that other threats will be able to see this update in case the threats has the
+
+99
+00:07:45,000 --> 00:07:46,000
+reference to the same object.
+
+100
+00:07:46,000 --> 00:07:50,000
+Without using proper synchronization or volatile keyword.
+
+101
+00:07:51,000 --> 00:07:58,000
+There is a chance that updates to the shared object made by one threat may not be visible to NSW.
+
+102
+00:07:58,000 --> 00:07:59,000
+How it may happen.
+
+103
+00:08:00,000 --> 00:08:01,000
+Let's imagine the next case.
+
+104
+00:08:01,000 --> 00:08:08,000
+Initially shared object is stored in RAM memory main memory and imagine the one thread that is running
+
+105
+00:08:08,000 --> 00:08:10,000
+on CPU object in the state of this object.
+
+106
+00:08:11,000 --> 00:08:17,000
+As long as a cache has not been flashed back to the main memory, the updated version of the shared
+
+107
+00:08:17,000 --> 00:08:22,000
+object is not visible to run on other CPU's.
+
+108
+00:08:22,000 --> 00:08:23,000
+Is that clear?
+
+109
+00:08:24,000 --> 00:08:31,000
+This may end up that each thread contains its own version of the same variable in different CPU cache
+
+110
+00:08:31,000 --> 00:08:32,000
+as slide.
+
+111
+00:08:32,000 --> 00:08:39,000
+You can see how to threats update the same account variable and until CPU cache memory isn't flashed,
+
+112
+00:08:39,000 --> 00:08:43,000
+these updates are sitting there to solve this issue.
+
+113
+00:08:43,000 --> 00:08:45,000
+We may use volatile keyword.
+
+114
+00:08:46,000 --> 00:08:49,000
+I will explain later what volatile keyword does.
+
+115
+00:08:50,000 --> 00:08:52,000
+Let's discuss the second issue race conditions.
+
+116
+00:08:53,000 --> 00:08:59,000
+Imagine that you have a variable account of a shared object, this variable and CPU cache of one threat
+
+117
+00:08:59,000 --> 00:09:01,000
+and in CPU a cache of another threat.
+
+118
+00:09:02,000 --> 00:09:06,000
+Both threats does the same thing they add the one does account.
+
+119
+00:09:06,000 --> 00:09:14,000
+Variable count has been incremented two times and then this program would run sequentially and each
+
+120
+00:09:14,000 --> 00:09:16,000
+threat update is a verbal one after another.
+
+121
+00:09:16,000 --> 00:09:19,000
+In this case, the value of Cowens variable would be true.
+
+122
+00:09:20,000 --> 00:09:22,000
+However, this is not the case.
+
+123
+00:09:22,000 --> 00:09:30,000
+The increments happened concurrently and we got last update because no matter which threat update version
+
+124
+00:09:30,000 --> 00:09:36,000
+of counts variable in main memory is updated, value will be overridden by another threat.
+
+125
+00:09:36,000 --> 00:09:39,000
+How to solve this synchronize blocks.
+
+126
+00:09:39,000 --> 00:09:45,000
+In this course you will learn how to use synchronize blocks properly to synchronize access of multiple
+
+127
+00:09:45,000 --> 00:09:47,000
+threats to critical sections.
+
+128
+00:09:47,000 --> 00:09:53,000
+I believe that now you understand how memory management is performed on different levels of the threat
+
+129
+00:09:53,000 --> 00:09:54,000
+in programs.
+
+130
+00:09:54,000 --> 00:09:59,000
+I promise you also to explain what volatile keywords is and how it works.
+
+131
+00:09:59,000 --> 00:10:02,000
+As you already can understand that Dune's and.
+
+132
+00:10:02,000 --> 00:10:10,000
+We should consider a lot of other things the process in flush its cash buffer in any order dude compiler
+
+133
+00:10:10,000 --> 00:10:11,000
+may optimize our execution.
+
+134
+00:10:11,000 --> 00:10:17,000
+We are ordering order and is an optimization technique for performance improvements.
+
+135
+00:10:17,000 --> 00:10:23,000
+When you write the program, you expect instructions will be executed in order as written in the program.
+
+136
+00:10:23,000 --> 00:10:25,000
+But that is not always the case.
+
+137
+00:10:25,000 --> 00:10:33,000
+For example, you may declare two fields in time that is equal to 10 and JS that is equal to five.
+
+138
+00:10:33,000 --> 00:10:34,000
+It might happen.
+
+139
+00:10:34,000 --> 00:10:42,000
+That variable is the second one in zero will be initialized first, but I variable still wouldn't be
+
+140
+00:10:42,000 --> 00:10:51,000
+initialized and has the zero value, but not then because zero is a default value for I so far.
+
+141
+00:10:51,000 --> 00:10:58,000
+Non-dependent operations like initialization of course fields in some case compiler may apply some optimizations
+
+142
+00:10:58,000 --> 00:11:01,000
+and the ordering is one of such techniques.
+
+143
+00:11:01,000 --> 00:11:08,000
+And in case I will use volatile keywords with the fields, this will be assigned for runtime environment
+
+144
+00:11:08,000 --> 00:11:11,000
+that I need predictable order for operations.
+
+145
+00:11:11,000 --> 00:11:15,000
+With these variables, orderings won't be applied to such variables.
+
+146
+00:11:15,000 --> 00:11:22,000
+And also I need to flash any updates to these variables instantly to make updates visible to all other
+
+147
+00:11:22,000 --> 00:11:22,000
+threats.
+
+148
+00:11:22,000 --> 00:11:27,000
+Does it make sense to explain how volatile works and why do we need it?
+
+149
+00:11:27,000 --> 00:11:34,000
+I had to explain your hardware, memory architecture and Java memory model, but now I believe it is
+
+150
+00:11:34,000 --> 00:11:38,000
+crystal clear what problem we are trying to solve by adding volatile keywords.
+
+151
+00:11:38,000 --> 00:11:45,000
+And now when I break, huge means that you would find in the Internet and in volatile Keever, it doesn't
+
+152
+00:11:45,000 --> 00:11:49,000
+mean that all operations with such variable will be atomic.
+
+153
+00:11:50,000 --> 00:11:57,000
+You may find statements in Internet and sometimes even on stack overflow that volatile variables behave
+
+154
+00:11:57,000 --> 00:11:59,000
+like atomic and operations.
+
+155
+00:11:59,000 --> 00:12:00,000
+That is not true.
+
+156
+00:12:01,000 --> 00:12:06,000
+The effect of volatile keywords is that approximately each individual read or write.
+
+157
+00:12:06,000 --> 00:12:11,000
+A separation on that variable is made atomically visible to all threads.
+
+158
+00:12:12,000 --> 00:12:14,000
+However, operations is.
+
+159
+00:12:14,000 --> 00:12:21,000
+It requires more than one redivide cycle, such as incremented, for example, will not be executed
+
+160
+00:12:21,000 --> 00:12:29,000
+as atomic because we need read value of the variable at one safe result of calculation and assign that
+
+161
+00:12:29,000 --> 00:12:35,000
+this variable Z separation's one V atomic, even if you will work with volatile variable.
+
+162
+00:12:36,000 --> 00:12:42,000
+Remember that only atomic operations I Stipe's from Java to concurrent atomic package.
+
+163
+00:12:43,000 --> 00:12:46,000
+We talked about these atomic types for a long time already.
+
+164
+00:12:47,000 --> 00:12:51,000
+Let me show them how to work with these types, first of all.
+
+165
+00:12:51,000 --> 00:12:57,000
+And as always, I recommended to start from the official documentation from Oracle, from documentation.
+
+166
+00:12:57,000 --> 00:13:04,000
+We see that this package is a small tool kit of classes that support locally safe programming on single
+
+167
+00:13:04,000 --> 00:13:04,000
+variables.
+
+168
+00:13:05,000 --> 00:13:07,000
+Here you can find class summary.
+
+169
+00:13:08,000 --> 00:13:13,000
+It is easy to remember these class names because most of them have atomic at the beginning.
+
+170
+00:13:14,000 --> 00:13:17,000
+Atomic Boulin Atomic Integer atomic bomb.
+
+171
+00:13:17,000 --> 00:13:21,000
+I bet you can understand what type of values these atomic types.
+
+172
+00:13:21,000 --> 00:13:28,000
+Berquist Atomic Reference is a type that describes an object reference that may be updated atomically.
+
+173
+00:13:29,000 --> 00:13:34,000
+Each of these types provide its own API to perform necessary operations.
+
+174
+00:13:34,000 --> 00:13:41,000
+Also that types to execute threats, safe operations with arrays, atomic integer array, atomic clock
+
+175
+00:13:41,000 --> 00:13:49,000
+array, atomic reference and the even more times, for example, double atter, you can use this type
+
+176
+00:13:49,000 --> 00:13:49,000
+to perform.
+
+177
+00:13:49,000 --> 00:13:51,000
+Swed safe addition of double's.
+
+178
+00:13:52,000 --> 00:13:56,000
+Let's jump to the code examples and I'll show you how to work with the Stipe's.
+
+179
+00:13:57,000 --> 00:14:03,000
+For example, here is a code that creates 10000 threats and update counter variable Baycol increment
+
+180
+00:14:03,000 --> 00:14:05,000
+massive protection.
+
+181
+00:14:05,000 --> 00:14:11,000
+That increment method is not a synchronized one and they also don't have any synchronized blocks here.
+
+182
+00:14:11,000 --> 00:14:16,000
+But this code is safe and the security from animal to certain issues.
+
+183
+00:14:17,000 --> 00:14:17,000
+Why?
+
+184
+00:14:18,000 --> 00:14:25,000
+Because my counter has type atomic integer that supports safe operations in increments.
+
+185
+00:14:25,000 --> 00:14:32,000
+Masset, I use API of atomic integer done in case and is incremental value I can use is I get an increment
+
+186
+00:14:32,000 --> 00:14:35,000
+or increment and get these.
+
+187
+00:14:35,000 --> 00:14:43,000
+Tomas's are logically difference in terms of what value you want to get before or after an increment.
+
+188
+00:14:43,000 --> 00:14:48,000
+Let's run this example and in console you will always find ten thousand.
+
+189
+00:14:48,000 --> 00:14:54,000
+That is because during increment operation as a threat, we're not able to update the counter variable
+
+190
+00:14:54,000 --> 00:14:55,000
+in parallel.
+
+191
+00:14:55,000 --> 00:14:57,000
+Let me open the source code of this time.
+
+192
+00:14:58,000 --> 00:15:02,000
+If you look at S1, you would find that the.
+
+193
+00:15:02,000 --> 00:15:10,000
+Plenty of useful assets, some of them are get and set masses get and add as a single operation if you
+
+194
+00:15:10,000 --> 00:15:18,000
+want to, some integer values also their atomic decrements, decrements and get and get in command and
+
+195
+00:15:18,000 --> 00:15:22,000
+the masses to convert atomic integer to as a primitive times.
+
+196
+00:15:22,000 --> 00:15:26,000
+The rest of the atomic rubber stamps work pretty similar.
+
+197
+00:15:26,000 --> 00:15:31,000
+And as always, in case of any questions, feel free to leave your question and comments below this
+
+198
+00:15:31,000 --> 00:15:32,000
+here.
+
+199
+00:15:32,000 --> 00:15:34,000
+And the last but not the least.
+
+200
+00:15:34,000 --> 00:15:37,000
+What I'd like to share with you for today is a thread local.
+
+201
+00:15:37,000 --> 00:15:40,000
+I have separate file was named for local demo.
+
+202
+00:15:40,000 --> 00:15:45,000
+But before we jump to an example, let's understand a little bit more about Fred.
+
+203
+00:15:45,000 --> 00:15:46,000
+Local time.
+
+204
+00:15:47,000 --> 00:15:50,000
+So local is a tribe that is declared in Java land package.
+
+205
+00:15:51,000 --> 00:15:55,000
+That means you don't need any additional income statements to start using.
+
+206
+00:15:55,000 --> 00:16:02,000
+This type of local allows us to store data that will be accessible only by a single one.
+
+207
+00:16:02,000 --> 00:16:03,000
+You might need this.
+
+208
+00:16:03,000 --> 00:16:09,000
+There might be cases where you don't want the threats, interact with the data of other threats and
+
+209
+00:16:09,000 --> 00:16:17,000
+adjusted the variables of local type differ from their normal counterparts in that each thread that
+
+210
+00:16:17,000 --> 00:16:23,000
+accesses one has its own independently initialized copy of the variable spread.
+
+211
+00:16:23,000 --> 00:16:29,000
+Local instances are typically private static fields and classes that we often associate state with a
+
+212
+00:16:29,000 --> 00:16:35,000
+threat, for example, a user, a yi or transactionally, something very specific to one single threat.
+
+213
+00:16:36,000 --> 00:16:38,000
+Now let's start with the practical part.
+
+214
+00:16:38,000 --> 00:16:41,000
+I declare a private static field of threat.
+
+215
+00:16:41,000 --> 00:16:49,000
+Local type parametrized by string threat local will be similar to wrapper you get and set object of
+
+216
+00:16:49,000 --> 00:16:51,000
+parametrized type into it.
+
+217
+00:16:51,000 --> 00:16:57,000
+You can just create an instance of certain local types like you usually do with all of the reference
+
+218
+00:16:57,000 --> 00:16:57,000
+types.
+
+219
+00:16:57,000 --> 00:17:04,000
+With the help of your keywords, you can also use static Masset with initial zaftig supplier as method
+
+220
+00:17:04,000 --> 00:17:07,000
+argument to initialize the variable.
+
+221
+00:17:07,000 --> 00:17:12,000
+If you're not familiar with lambda expressions and supplier type, I recommend it to pass my functional
+
+222
+00:17:12,000 --> 00:17:14,000
+programming course for Java engineers.
+
+223
+00:17:15,000 --> 00:17:21,000
+There are a lot of examples that will explain the topic of lambda expressions and functional interfaces.
+
+224
+00:17:21,000 --> 00:17:27,000
+Let's move on for the sake of the demo and to make it as simple as possible, I will keep my thread
+
+225
+00:17:27,000 --> 00:17:32,000
+local parametrized by integer type and I will create object with new keyword.
+
+226
+00:17:33,000 --> 00:17:35,000
+After that I implement Runnable interface.
+
+227
+00:17:35,000 --> 00:17:41,000
+In this time, in run unmastered, I set random value from zero to one hundred does a transaction I
+
+228
+00:17:42,000 --> 00:17:43,000
+with the local variable.
+
+229
+00:17:43,000 --> 00:17:46,000
+After that I made my sleep for one second.
+
+230
+00:17:47,000 --> 00:17:49,000
+I am doing this for the sake of the demo.
+
+231
+00:17:49,000 --> 00:17:56,000
+During one second we can guarantee that both threads will be started and it is one hundred percent assurance
+
+232
+00:17:56,000 --> 00:17:59,000
+that this set method will be involved in one.
+
+233
+00:18:00,000 --> 00:18:03,000
+And then as a threat, I have to sleep in one second.
+
+234
+00:18:03,000 --> 00:18:07,000
+I print the value of thread local to cancel all threads.
+
+235
+00:18:07,000 --> 00:18:12,000
+Technically, I need to create threads, objects and start them and pay attention.
+
+236
+00:18:12,000 --> 00:18:19,000
+Transaction ID is a static variable and we may assume that it exists in single copy, but both threads
+
+237
+00:18:19,000 --> 00:18:22,000
+will have different values associated with this variable.
+
+238
+00:18:23,000 --> 00:18:24,000
+Don't believe me.
+
+239
+00:18:24,000 --> 00:18:27,000
+Let's run the program after one second pause.
+
+240
+00:18:27,000 --> 00:18:28,000
+I see.
+
+241
+00:18:28,000 --> 00:18:32,000
+And so the two threads print printed different values of the same static variable.
+
+242
+00:18:33,000 --> 00:18:39,000
+How this has happened, you can imagine the thread local is a map in this map.
+
+243
+00:18:39,000 --> 00:18:45,000
+This thread is a key and the value is the values that we set our thread local variable.
+
+244
+00:18:45,000 --> 00:18:50,000
+And when I get value, I just extract that using the key mussarat object.
+
+245
+00:18:51,000 --> 00:18:52,000
+That's why you shouldn't.
+
+246
+00:18:52,000 --> 00:18:55,000
+Or is it another stretchable access value from another thread?
+
+247
+00:18:56,000 --> 00:19:00,000
+And that values that you said in one thread will be our written in other thread.
+
+248
+00:19:01,000 --> 00:19:03,000
+And one more thing related to thread local.
+
+249
+00:19:03,000 --> 00:19:06,000
+We have another type that extends throughout local.
+
+250
+00:19:06,000 --> 00:19:08,000
+It is inheritable Sareb local.
+
+251
+00:19:09,000 --> 00:19:10,000
+What is the difference?
+
+252
+00:19:10,000 --> 00:19:17,000
+Instead of each thread having its own value inside the local is inheritable spread local grants, access
+
+253
+00:19:17,000 --> 00:19:22,000
+to RELISTOR threat and all child threats created by the threat.
+
+254
+00:19:22,000 --> 00:19:25,000
+Let's look at the example I have read local variable.
+
+255
+00:19:26,000 --> 00:19:28,000
+This is parametrized by type string.
+
+256
+00:19:28,000 --> 00:19:30,000
+Nothing special here.
+
+257
+00:19:30,000 --> 00:19:33,000
+And the next field has inheritable spread local time.
+
+258
+00:19:34,000 --> 00:19:36,000
+I create the instance of this type with the help of you.
+
+259
+00:19:36,000 --> 00:19:40,000
+Keeva, let's run this app and look at the main message.
+
+260
+00:19:40,000 --> 00:19:47,000
+Now, I read the first thread and I said the local value and inheritable spread local value.
+
+261
+00:19:47,000 --> 00:19:51,000
+After that, I print values that are stored inside these two variables.
+
+262
+00:19:52,000 --> 00:19:56,000
+And as you can see in console, everything is straightforward here.
+
+263
+00:19:56,000 --> 00:19:59,000
+I can see value of the variables after that.
+
+264
+00:19:59,000 --> 00:20:01,000
+Inside this threat, I create a large.
+
+265
+00:20:01,000 --> 00:20:08,000
+A threat, this threat is a child's threat and the values of state, local and inheritable threat,
+
+266
+00:20:08,000 --> 00:20:14,000
+local variables here and in Arkansas, you can see that I don't have access to the threat local variable
+
+267
+00:20:14,000 --> 00:20:17,000
+on this level, but I can see inheritable threat, local value.
+
+268
+00:20:17,000 --> 00:20:21,000
+And after that, I create a separate threat threat.
+
+269
+00:20:21,000 --> 00:20:24,000
+Number two, I make it sleep for one second.
+
+270
+00:20:24,000 --> 00:20:29,000
+And after that, I want to bring the values of threat local and inheritable threat local.
+
+271
+00:20:30,000 --> 00:20:36,000
+And as you may already understand, the threat of local law, inheritable threat local is accessible
+
+272
+00:20:36,000 --> 00:20:37,000
+from a national threat.
+
+273
+00:20:37,000 --> 00:20:39,000
+Hope that this example is clear for you.
+
+274
+00:20:39,000 --> 00:20:43,000
+And you know what a threat to local and what is inheritable threat local.
+
+275
+00:20:44,000 --> 00:20:46,000
+Let's review what we have learned in this lesson.
+
+276
+00:20:46,000 --> 00:20:50,000
+In this lesson, we learned how memory is managed in most training programs.
+
+277
+00:20:51,000 --> 00:20:56,000
+Also now, you know, hardware, memory, architecture and how German memory model uses memory.
+
+278
+00:20:57,000 --> 00:21:01,000
+All this let us understand whether volatile keyword and why we needed.
+
+279
+00:21:02,000 --> 00:21:09,000
+After that, we performed over of two concurrent atomic package and so atomic integer example.
+
+280
+00:21:09,000 --> 00:21:14,000
+And at the end of the lesson we learned to read local type and inheritable are local.
+
+281
+00:21:15,000 --> 00:21:16,000
+That's it for this lesson.
+
+282
+00:21:16,000 --> 00:21:18,000
+Thanks a lot for your attention.
+
+283
+00:21:18,000 --> 00:21:21,000
+Have a great day and see you in the next lesson.
+
diff --git a/27 - Multithreading/005 ThreadLocal-demo-source-code.url b/27 - Multithreading/005 ThreadLocal-demo-source-code.url
new file mode 100644
index 0000000000000000000000000000000000000000..9c9a4587eab7f13058489b35ae62b8859af55f5e
--- /dev/null
+++ b/27 - Multithreading/005 ThreadLocal-demo-source-code.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/ThreadLocalDemo.java
\ No newline at end of file
diff --git a/27 - Multithreading/006 Deadlock & Livelock_en.srt b/27 - Multithreading/006 Deadlock & Livelock_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..cef8140a515b0fe07104104be49e5e27869d0bc3
--- /dev/null
+++ b/27 - Multithreading/006 Deadlock & Livelock_en.srt
@@ -0,0 +1,716 @@
+1
+00:00:05,000 --> 00:00:10,000
+Hello, Jim, in this nice little talk about deadlocks and live looks at the beginning of the lesson,
+
+2
+00:00:10,000 --> 00:00:14,000
+I will explain to you what the deadlock is and what liveblog is.
+
+3
+00:00:14,000 --> 00:00:20,000
+One of the real examples will reproduce results such states and you will understand what to do to avoid
+
+4
+00:00:20,000 --> 00:00:22,000
+states of deadlock and live.
+
+5
+00:00:22,000 --> 00:00:23,000
+Look, let's stop.
+
+6
+00:00:24,000 --> 00:00:26,000
+Let's understand first what a deadlock is.
+
+7
+00:00:26,000 --> 00:00:33,000
+The definition of simple deadlock is a state where two or more threats are blocked forever, waiting
+
+8
+00:00:33,000 --> 00:00:33,000
+for each other.
+
+9
+00:00:34,000 --> 00:00:35,000
+How it may happen.
+
+10
+00:00:35,000 --> 00:00:41,000
+This situation may happen when two or more threats require the same locks, but obtain them in different
+
+11
+00:00:41,000 --> 00:00:42,000
+order.
+
+12
+00:00:42,000 --> 00:00:49,000
+And to be honest, it is really hard to fall into the trap of deadlock nowadays because modern tools
+
+13
+00:00:49,000 --> 00:00:55,000
+for work and was able to threaten provide us with API to try acquire, look within a specific time and
+
+14
+00:00:55,000 --> 00:00:58,000
+precede execution in case lock is not acquired.
+
+15
+00:00:59,000 --> 00:01:02,000
+Having to explain such concepts in the next lessons.
+
+16
+00:01:02,000 --> 00:01:07,000
+But you need to understand Dedlock case so that you would understand the motivation to use all the tools
+
+17
+00:01:07,000 --> 00:01:13,000
+and classes that we are going to go into following the lessons you might have that look state in your
+
+18
+00:01:13,000 --> 00:01:19,000
+app when you use synchronized methods or synchronized blocks, lets her use the next theoretical example.
+
+19
+00:01:19,000 --> 00:01:22,000
+Imagine that you have two threats and you have to.
+
+20
+00:01:22,000 --> 00:01:27,000
+WLOX threat number one captured the first lock and tries to acquire the second lock.
+
+21
+00:01:27,000 --> 00:01:34,000
+But at this moment, threat number two already got the second lock and tries to get the first lock.
+
+22
+00:01:34,000 --> 00:01:36,000
+And here is a deadlock threat.
+
+23
+00:01:36,000 --> 00:01:38,000
+No one will never get the second lock.
+
+24
+00:01:39,000 --> 00:01:39,000
+Why?
+
+25
+00:01:40,000 --> 00:01:46,000
+Because threat number two holds the second lock and will not release it until it would get the first
+
+26
+00:01:46,000 --> 00:01:46,000
+look.
+
+27
+00:01:46,000 --> 00:01:53,000
+But he already knows that the first look is not released by threat number one until threat number one
+
+28
+00:01:53,000 --> 00:01:54,000
+will get the second lock.
+
+29
+00:01:55,000 --> 00:02:01,000
+And here's a case when two threats are waiting for a lock that is acquired by another threat, how to
+
+30
+00:02:01,000 --> 00:02:04,000
+solve this theoretical example and avoid a deadlock.
+
+31
+00:02:04,000 --> 00:02:06,000
+There are actually few options here.
+
+32
+00:02:07,000 --> 00:02:11,000
+The first and the easiest one with acquiring multiple locks by threat.
+
+33
+00:02:12,000 --> 00:02:14,000
+In the case, threats need to acquire multiple locks.
+
+34
+00:02:15,000 --> 00:02:19,000
+The next options, the second option is to make sure you follow this rule.
+
+35
+00:02:20,000 --> 00:02:23,000
+Always request locks in the same order in all threats.
+
+36
+00:02:24,000 --> 00:02:30,000
+For example, if only we requested the first lock by threat number one and the first lock by threat
+
+37
+00:02:30,000 --> 00:02:33,000
+number two, we wouldn't be in deadlock state.
+
+38
+00:02:33,000 --> 00:02:40,000
+And another solution is to use time restrictions to limit time of lock acquiring, for example, in
+
+39
+00:02:40,000 --> 00:02:42,000
+case threat didn't obtain.
+
+40
+00:02:42,000 --> 00:02:45,000
+Look within the specific time threat keeps execution.
+
+41
+00:02:46,000 --> 00:02:52,000
+In this case, threat is not blocked for infinite amount of time in case it is unable to acquire a lock.
+
+42
+00:02:53,000 --> 00:02:58,000
+Hope that now it is clear for you what a deadlock is and how theoretically to avoid it.
+
+43
+00:02:58,000 --> 00:03:00,000
+Let's now look at court examples.
+
+44
+00:03:00,000 --> 00:03:03,000
+We'll reproduce Deadlock State and we'll fix it.
+
+45
+00:03:04,000 --> 00:03:06,000
+I have that look issue demo class.
+
+46
+00:03:06,000 --> 00:03:10,000
+You can find the source code of all examples in attachments to this lesson.
+
+47
+00:03:10,000 --> 00:03:12,000
+I declare two fields here.
+
+48
+00:03:12,000 --> 00:03:15,000
+I call them lock one and lock two.
+
+49
+00:03:15,000 --> 00:03:19,000
+I will use these objects for synchronization in main method.
+
+50
+00:03:19,000 --> 00:03:24,000
+I declare to threats and instantly start out in the first thread.
+
+51
+00:03:24,000 --> 00:03:30,000
+I capture lock number one and imitate some time consuming operation by making my thread sleep for half
+
+52
+00:03:30,000 --> 00:03:33,000
+of the second instead of this sleep operation.
+
+53
+00:03:33,000 --> 00:03:36,000
+Could be any other time consuming operation.
+
+54
+00:03:36,000 --> 00:03:41,000
+After that, I tried to capture lock number two buttons.
+
+55
+00:03:41,000 --> 00:03:43,000
+This example will never enter.
+
+56
+00:03:43,000 --> 00:03:46,000
+Block and Sweat will be waiting to capture more control of the lock.
+
+57
+00:03:46,000 --> 00:03:52,000
+No, to object because the monitor of the second lock will never be released.
+
+58
+00:03:52,000 --> 00:03:53,000
+Let me explain why.
+
+59
+00:03:54,000 --> 00:03:58,000
+So this threat is started and I create a new threat in this new threat.
+
+60
+00:03:58,000 --> 00:04:03,000
+I capture second lock and after that I try to capture lock number one.
+
+61
+00:04:04,000 --> 00:04:10,000
+But I can because it is still captured by the first threat and the first threat can't capture lock number
+
+62
+00:04:10,000 --> 00:04:15,000
+two because it won't be released until the second threat will release the lock.
+
+63
+00:04:16,000 --> 00:04:18,000
+And that's how we get to the deadlock state.
+
+64
+00:04:18,000 --> 00:04:25,000
+Let's run this program and you can see that I printed information about capturing lock objects and GBM
+
+65
+00:04:25,000 --> 00:04:26,000
+is working.
+
+66
+00:04:26,000 --> 00:04:32,000
+It is actually does nothing at the moment because the threats just waiting until logs will be released.
+
+67
+00:04:33,000 --> 00:04:35,000
+But we understand that they won't be released.
+
+68
+00:04:36,000 --> 00:04:37,000
+Let's now try to figure this.
+
+69
+00:04:38,000 --> 00:04:42,000
+So the first fix is not to use multiple locks in one threat.
+
+70
+00:04:42,000 --> 00:04:44,000
+That is the easiest one.
+
+71
+00:04:44,000 --> 00:04:46,000
+And I believe I even don't need to demo this.
+
+72
+00:04:47,000 --> 00:04:50,000
+You just remove the second synchronized lock and that's it.
+
+73
+00:04:50,000 --> 00:04:57,000
+The second fix is to capture locks in the same order I open Dedlock solution demo class.
+
+74
+00:04:57,000 --> 00:04:59,000
+This is a similar example.
+
+75
+00:04:59,000 --> 00:05:00,000
+Was only a few changes in.
+
+76
+00:05:00,000 --> 00:05:06,000
+The second threat will capture look one first and after that will capture second block.
+
+77
+00:05:06,000 --> 00:05:12,000
+Let me run the program and you can see that all lines of code are executed because in this case, we
+
+78
+00:05:12,000 --> 00:05:13,000
+don't have that look.
+
+79
+00:05:14,000 --> 00:05:17,000
+And the third fix is to use time block at times.
+
+80
+00:05:18,000 --> 00:05:22,000
+But we learn how to use API in obsolescence dedicated to lock API.
+
+81
+00:05:23,000 --> 00:05:24,000
+So that's it.
+
+82
+00:05:24,000 --> 00:05:27,000
+Now, you know what the deadlock state is and how to avoid it.
+
+83
+00:05:28,000 --> 00:05:30,000
+Let's now learn what life is.
+
+84
+00:05:31,000 --> 00:05:36,000
+Another issue that might appear during the execution of each Australian program is a live look state.
+
+85
+00:05:37,000 --> 00:05:37,000
+What is it?
+
+86
+00:05:38,000 --> 00:05:42,000
+Look, it's similar to the deadlock in terms of the end result.
+
+87
+00:05:42,000 --> 00:05:49,000
+Program will not produce any useful output, but different in terms of the root cause and actual state
+
+88
+00:05:49,000 --> 00:05:50,000
+of the program in life.
+
+89
+00:05:50,000 --> 00:05:56,000
+Look to term threats, keep on transferring states between each other instead of just waiting like we
+
+90
+00:05:56,000 --> 00:05:57,000
+saw in Dedlock.
+
+91
+00:05:57,000 --> 00:06:01,000
+Example, in the case of liveblog, threats are not blocked.
+
+92
+00:06:01,000 --> 00:06:06,000
+Actually, they're just too busy responding to each other to resume work.
+
+93
+00:06:06,000 --> 00:06:11,000
+This is comparable to two people attempting to pass each other in the corridor.
+
+94
+00:06:12,000 --> 00:06:17,000
+So imagine that you're faced with a friend of yours in the corridor and you decided to move left to
+
+95
+00:06:17,000 --> 00:06:19,000
+let your friend pass you.
+
+96
+00:06:19,000 --> 00:06:24,000
+But your friend is also polite and he decided to move right to let you pass.
+
+97
+00:06:24,000 --> 00:06:26,000
+But you blocked each other again.
+
+98
+00:06:27,000 --> 00:06:28,000
+Now you decide to move.
+
+99
+00:06:28,000 --> 00:06:28,000
+Right.
+
+100
+00:06:29,000 --> 00:06:35,000
+But friend of yours thinks that he's also responsible for what happened and he decided to move left
+
+101
+00:06:35,000 --> 00:06:35,000
+this time.
+
+102
+00:06:35,000 --> 00:06:39,000
+And both of you are blocked again in the corridor and so on.
+
+103
+00:06:40,000 --> 00:06:46,000
+How to avoid lock down with LifeLock when you to investigate the conditions that causes lifelong state
+
+104
+00:06:47,000 --> 00:06:49,000
+to come up with solution accordingly.
+
+105
+00:06:49,000 --> 00:06:56,000
+So it is no universal solution to address Lifebook issue as threat should stop repeating the same actions
+
+106
+00:06:56,000 --> 00:07:03,000
+if no progress has been detected and real life scenarios may be very different case by case, let me
+
+107
+00:07:03,000 --> 00:07:04,000
+show you a LifeLock example.
+
+108
+00:07:05,000 --> 00:07:07,000
+Will reproduce LifeLock state and will fix it.
+
+109
+00:07:08,000 --> 00:07:13,000
+I open LifeLock issued demo class will imitate family dinner.
+
+110
+00:07:13,000 --> 00:07:18,000
+Imagine that we have one spoon and two spouses, wife and husband, eager.
+
+111
+00:07:19,000 --> 00:07:23,000
+They are going to have a dinner, but they have only one spoon by default.
+
+112
+00:07:23,000 --> 00:07:27,000
+Husband capture the spoon and after that I ran through threats.
+
+113
+00:07:27,000 --> 00:07:33,000
+One read for husband, where I call it with Massive and I pass spoon and spouse.
+
+114
+00:07:34,000 --> 00:07:37,000
+And a similar threat was called in the same method for wife.
+
+115
+00:07:37,000 --> 00:07:43,000
+She is a glass of the spoon it has on the getter setter and use method.
+
+116
+00:07:44,000 --> 00:07:48,000
+Satur and use methods are synchronized when you smash at this code.
+
+117
+00:07:48,000 --> 00:07:53,000
+I put in the name of the spoon owner to indicate who used the spoon.
+
+118
+00:07:53,000 --> 00:07:55,000
+And here is the spouse class.
+
+119
+00:07:55,000 --> 00:07:59,000
+It has two properties name and is hungry.
+
+120
+00:07:59,000 --> 00:08:01,000
+FLAC by default is hungry.
+
+121
+00:08:01,000 --> 00:08:02,000
+Property is true.
+
+122
+00:08:02,000 --> 00:08:05,000
+Let's look at it with MassArt.
+
+123
+00:08:05,000 --> 00:08:09,000
+This is exactly the message that we are executing in our two threads.
+
+124
+00:08:09,000 --> 00:08:16,000
+I have loop here that checks was a spouse is hungry and if yes, then any check whether the spouse opens
+
+125
+00:08:16,000 --> 00:08:17,000
+a spoon at this moment.
+
+126
+00:08:18,000 --> 00:08:23,000
+If no, I just wait for one second and go to the next iteration in the loop.
+
+127
+00:08:23,000 --> 00:08:28,000
+During this one second, I expect my spouse would eat and will give me the spoon.
+
+128
+00:08:29,000 --> 00:08:34,000
+But this logic will bring this to the state when two spouses constantly changing the owner of the spoon,
+
+129
+00:08:35,000 --> 00:08:37,000
+one spouse is an owner of a spoon.
+
+130
+00:08:37,000 --> 00:08:40,000
+I verify whether my spouse is hungry.
+
+131
+00:08:40,000 --> 00:08:41,000
+Pay attention.
+
+132
+00:08:41,000 --> 00:08:45,000
+I pass the reference to my spouse in the of IT twist.
+
+133
+00:08:45,000 --> 00:08:51,000
+That's why I have the reference to object of as a spouse and I can verify it's said.
+
+134
+00:08:51,000 --> 00:08:55,000
+And as you remember, all spouses are hungry by default.
+
+135
+00:08:55,000 --> 00:09:03,000
+That's why I enter this if block and we change in of of a spoon because each spouse is worrying about
+
+136
+00:09:03,000 --> 00:09:07,000
+another one and one spoon is passed to a spouse.
+
+137
+00:09:07,000 --> 00:09:10,000
+I jump to another iteration of the slope.
+
+138
+00:09:10,000 --> 00:09:13,000
+Let's run the app and see what we have.
+
+139
+00:09:13,000 --> 00:09:20,000
+And as we can see in console, the threats are not that they're working, but they're constantly passing
+
+140
+00:09:20,000 --> 00:09:23,000
+the spoon to each other without eating at all.
+
+141
+00:09:24,000 --> 00:09:32,000
+Because I used Masset on a spoon only after that last if block and my app never reaches this point in
+
+142
+00:09:32,000 --> 00:09:34,000
+either of the threads how to solve this.
+
+143
+00:09:35,000 --> 00:09:40,000
+I stobbs it at first and start thinking, let's analyze how to solve this case.
+
+144
+00:09:41,000 --> 00:09:46,000
+Actually, there are different ways to solve this issue and only one of them is to limit the number
+
+145
+00:09:46,000 --> 00:09:54,000
+of person spoon between spouses, for example, if eager to spoon to master once and she returns it
+
+146
+00:09:54,000 --> 00:09:54,000
+back.
+
+147
+00:09:55,000 --> 00:09:56,000
+That means gurmai it.
+
+148
+00:09:57,000 --> 00:10:00,000
+The same rule applies for Nasta too I.
+
+149
+00:10:00,000 --> 00:10:05,000
+Open life solution file where I resolved the issue to solve it.
+
+150
+00:10:05,000 --> 00:10:08,000
+I introduce two more fields in spouse's time.
+
+151
+00:10:09,000 --> 00:10:12,000
+The first one is Spoonbill Times.
+
+152
+00:10:12,000 --> 00:10:18,000
+This number of times we pass the spoon to the spouse and let he or she eat first.
+
+153
+00:10:19,000 --> 00:10:22,000
+The next new in the field is spoon field limit.
+
+154
+00:10:23,000 --> 00:10:27,000
+This variable will stores a limited number of persons pool to a spouse.
+
+155
+00:10:28,000 --> 00:10:30,000
+Initializes field was one.
+
+156
+00:10:30,000 --> 00:10:35,000
+This means that in the case I already passed my spoon at least once in the past.
+
+157
+00:10:35,000 --> 00:10:38,000
+I am not passing it to another spouse again.
+
+158
+00:10:39,000 --> 00:10:45,000
+I increments Poolesville times when I am changing owner of a spoon and before changing owner of the
+
+159
+00:10:45,000 --> 00:10:46,000
+spoon.
+
+160
+00:10:46,000 --> 00:10:51,000
+I also verify whether I passed the spoon to a spouse previously, in past or not.
+
+161
+00:10:52,000 --> 00:10:58,000
+In this case, each spouse can pass the spoon only once, and after that he or she will start to use
+
+162
+00:10:58,000 --> 00:10:59,000
+a spoon to eat.
+
+163
+00:11:00,000 --> 00:11:01,000
+Let's check this.
+
+164
+00:11:01,000 --> 00:11:09,000
+I ran the program in so we can see that Igor suggested I to eat, but Nastia refused and suggested eager
+
+165
+00:11:09,000 --> 00:11:09,000
+to eat.
+
+166
+00:11:10,000 --> 00:11:16,000
+This time IGR didn't play this game of polite husband and she started to eat inconsolably.
+
+167
+00:11:16,000 --> 00:11:23,000
+Indicated that Eagler has eaten after that without Nastia, that Eger is stuffed and is not hungry anymore,
+
+168
+00:11:24,000 --> 00:11:26,000
+and after that Nasta has eaten.
+
+169
+00:11:27,000 --> 00:11:28,000
+Pay attention to this time.
+
+170
+00:11:28,000 --> 00:11:31,000
+DVM is stopped and we don't have LifeLock.
+
+171
+00:11:32,000 --> 00:11:33,000
+Is that clear?
+
+172
+00:11:34,000 --> 00:11:34,000
+Great.
+
+173
+00:11:34,000 --> 00:11:41,000
+Now let's review what we have learned in this lesson, this lesson learned, what a deadlock is and
+
+174
+00:11:41,000 --> 00:11:44,000
+what a live look as we reproduce with your Dedlock and life.
+
+175
+00:11:44,000 --> 00:11:47,000
+Look on both examples after this lesson.
+
+176
+00:11:47,000 --> 00:11:51,000
+You know how to avoid deadlock and how to avoid LifeLock.
+
+177
+00:11:52,000 --> 00:11:53,000
+That's it for this lesson.
+
+178
+00:11:53,000 --> 00:11:55,000
+Thanks a lot for your attention.
+
+179
+00:11:55,000 --> 00:11:57,000
+Have a great day and see you in the next lesson.
+
diff --git a/27 - Multithreading/006 Deadlock-source-code-examples.url b/27 - Multithreading/006 Deadlock-source-code-examples.url
new file mode 100644
index 0000000000000000000000000000000000000000..3bd744f3f0cb1d11788b372a0a997a01f2eb4bd1
--- /dev/null
+++ b/27 - Multithreading/006 Deadlock-source-code-examples.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/deadlock
\ No newline at end of file
diff --git a/27 - Multithreading/006 Livelock-source-code-examples.url b/27 - Multithreading/006 Livelock-source-code-examples.url
new file mode 100644
index 0000000000000000000000000000000000000000..aa91d4160a0c11c56777992deedce836f123e288
--- /dev/null
+++ b/27 - Multithreading/006 Livelock-source-code-examples.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/livelock
\ No newline at end of file
diff --git a/27 - Multithreading/007 Callable-Future-source-code-of-demo.url b/27 - Multithreading/007 Callable-Future-source-code-of-demo.url
new file mode 100644
index 0000000000000000000000000000000000000000..1a82f0375a7acce04c61af9dc7044364e2fffa9b
--- /dev/null
+++ b/27 - Multithreading/007 Callable-Future-source-code-of-demo.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/callable
\ No newline at end of file
diff --git a/27 - Multithreading/007 Executor Services, Callable & Future_en.srt b/27 - Multithreading/007 Executor Services, Callable & Future_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..61c82dde2326ae8acc2ec2750db724481579b6d2
--- /dev/null
+++ b/27 - Multithreading/007 Executor Services, Callable & Future_en.srt
@@ -0,0 +1,976 @@
+1
+00:00:05,000 --> 00:00:10,000
+Hello, adjustments in this lesson, we are going to learn really powerful tools to work with multiple
+
+2
+00:00:10,000 --> 00:00:12,000
+threats and to manage all threats.
+
+3
+00:00:13,000 --> 00:00:19,000
+In this lesson, I will explain the concepts of Executor's Booleroo executive and executive service
+
+4
+00:00:19,000 --> 00:00:20,000
+interfaces.
+
+5
+00:00:20,000 --> 00:00:23,000
+You will learn what the threat is today.
+
+6
+00:00:23,000 --> 00:00:29,000
+We're going to have a lot of examples and you will see how you can start threats with executive service.
+
+7
+00:00:29,000 --> 00:00:35,000
+Also today will run what the CORBEL interface is and what future type is.
+
+8
+00:00:35,000 --> 00:00:41,000
+And at the end of the lesson, we will learn how to interrupt all threats in executive service properly.
+
+9
+00:00:41,000 --> 00:00:45,000
+And as I already said before, so they are going to have a lot of examples.
+
+10
+00:00:45,000 --> 00:00:51,000
+Let me Starscream Sharon and will learn with you this topic by reviewing source code and examples I
+
+11
+00:00:51,000 --> 00:00:53,000
+open executer interface.
+
+12
+00:00:54,000 --> 00:00:57,000
+Let's understand first what this type is about and why do we need it.
+
+13
+00:00:58,000 --> 00:01:01,000
+Objects of exactly the type executes submitted Trunchbull tasks.
+
+14
+00:01:02,000 --> 00:01:08,000
+This interface provides a way of the Coplin task submission from the mechanics of how each task will
+
+15
+00:01:08,000 --> 00:01:15,000
+be run, including details of threat use, scheduling, etc. and executer is normally used instead of
+
+16
+00:01:15,000 --> 00:01:22,000
+explicitly creating threats, for example, rather than create a new threat object person Runnable as
+
+17
+00:01:22,000 --> 00:01:28,000
+constructor argument and Carlstadt method for each task you may use to execute Masset of executer type.
+
+18
+00:01:29,000 --> 00:01:36,000
+So as you can see this interface declare on the one MassArt execute that takes Runnable Executor's are
+
+19
+00:01:36,000 --> 00:01:42,000
+capable of running asynchronous tasks and typically manage a pool of threats so we don't have to create
+
+20
+00:01:42,000 --> 00:01:44,000
+new threats manually.
+
+21
+00:01:44,000 --> 00:01:48,000
+Probably this is the first time in this course when I mentioned streetball.
+
+22
+00:01:48,000 --> 00:01:49,000
+What is it?
+
+23
+00:01:49,000 --> 00:01:53,000
+A threat pool is a software design part in programming.
+
+24
+00:01:53,000 --> 00:01:59,000
+Threat pool maintains multiple threats, waiting for tasks to be allocated for concurrent execution
+
+25
+00:01:59,000 --> 00:02:01,000
+by the supervising program.
+
+26
+00:02:01,000 --> 00:02:09,000
+By maintaining this pool, the model increases performance and avoids latency in execution due to frequent
+
+27
+00:02:09,000 --> 00:02:12,000
+creation and destruction of threats for short life tasks.
+
+28
+00:02:13,000 --> 00:02:16,000
+Because creation of a threat object also takes some time.
+
+29
+00:02:17,000 --> 00:02:23,000
+And why should create ten thousand threats for ten thousand tasks that are relatively small and fast?
+
+30
+00:02:23,000 --> 00:02:28,000
+It would be a great idea to reduce threats that were created already for new tasks.
+
+31
+00:02:28,000 --> 00:02:32,000
+I agree, but how much threats we need to create initially?
+
+32
+00:02:33,000 --> 00:02:35,000
+We will get back to this question later.
+
+33
+00:02:35,000 --> 00:02:42,000
+All threats of the internal pool will be reduced under the hood for relevant task so that we can run
+
+34
+00:02:42,000 --> 00:02:47,000
+as many concurrent tasks as we want throughout the lifecycle of our application.
+
+35
+00:02:47,000 --> 00:02:53,000
+With a single executor, there is another popular interface that extends this one.
+
+36
+00:02:53,000 --> 00:02:55,000
+It is called Executive Service.
+
+37
+00:02:55,000 --> 00:03:01,000
+And to be honest, there is not so much popular direct implementations of executer interface.
+
+38
+00:03:01,000 --> 00:03:06,000
+More often will use implementations of executive service interface.
+
+39
+00:03:06,000 --> 00:03:12,000
+Let's try to understand what is the difference between these two types and why we need executive service.
+
+40
+00:03:13,000 --> 00:03:18,000
+This type introduces new behavior with help of executive services.
+
+41
+00:03:18,000 --> 00:03:22,000
+I may manage termination of all threats and not complete the tasks.
+
+42
+00:03:22,000 --> 00:03:28,000
+And in addition to that, we can submit tasks for execution that will return US future objects.
+
+43
+00:03:29,000 --> 00:03:34,000
+We will be able to give the result of computation by a separate task in the future.
+
+44
+00:03:34,000 --> 00:03:41,000
+Here in Method Outline, you can see a group of mass that allow us to terminate all tasks properly.
+
+45
+00:03:41,000 --> 00:03:44,000
+I will show you in a few minutes how to work with them.
+
+46
+00:03:44,000 --> 00:03:49,000
+We have submitted method that allows us to submit tasks for execution.
+
+47
+00:03:49,000 --> 00:03:52,000
+I can submit both types, runnable and callable.
+
+48
+00:03:53,000 --> 00:03:56,000
+I will also explain what Kobold type is in this lesson.
+
+49
+00:03:57,000 --> 00:04:02,000
+Also, we have a group of methods to manipulate with group of tasks during the tasks submission I'm
+
+50
+00:04:02,000 --> 00:04:05,000
+talking about, invoke vocal and invoke any methods.
+
+51
+00:04:06,000 --> 00:04:10,000
+Let's jump from certain code of interfaces to code examples.
+
+52
+00:04:10,000 --> 00:04:13,000
+I have a separate package here that is called Executor's.
+
+53
+00:04:13,000 --> 00:04:19,000
+It contains all examples related, was executed and execute the services.
+
+54
+00:04:19,000 --> 00:04:21,000
+I opened our first example.
+
+55
+00:04:21,000 --> 00:04:26,000
+The class name is execute with execute the service in line method accurate.
+
+56
+00:04:26,000 --> 00:04:28,000
+Our first executive service.
+
+57
+00:04:28,000 --> 00:04:29,000
+How to create it.
+
+58
+00:04:30,000 --> 00:04:33,000
+We have factory masses in execute first class.
+
+59
+00:04:33,000 --> 00:04:39,000
+If we open execute first class source code, you may find a lot of static methods that returns a reference
+
+60
+00:04:39,000 --> 00:04:41,000
+to the executive service.
+
+61
+00:04:41,000 --> 00:04:44,000
+These factory methods are started with new work.
+
+62
+00:04:45,000 --> 00:04:49,000
+We will learn the words use a difference between different implementations of executive services.
+
+63
+00:04:50,000 --> 00:04:53,000
+But at this moment, let's start from the simple things.
+
+64
+00:04:53,000 --> 00:04:55,000
+Let's get back to the demo file.
+
+65
+00:04:55,000 --> 00:04:59,000
+One of the most popular executive services is a cash thread.
+
+66
+00:04:59,000 --> 00:05:03,000
+Paul Aykroyd's the object of executive service here.
+
+67
+00:05:03,000 --> 00:05:10,000
+After that, I call execute MassArt and pass the runnable simple animal that just prints, threatening
+
+68
+00:05:10,000 --> 00:05:14,000
+to console, and I can execute another task in a similar way.
+
+69
+00:05:14,000 --> 00:05:16,000
+Let me run the program now.
+
+70
+00:05:16,000 --> 00:05:21,000
+And in console, you may see the name of the threat from our cached thread pool.
+
+71
+00:05:21,000 --> 00:05:25,000
+Probably you want to ask me right now and I can with us.
+
+72
+00:05:26,000 --> 00:05:30,000
+This example is much simpler than creating a thread and starting this thread.
+
+73
+00:05:30,000 --> 00:05:32,000
+Please don't think like this.
+
+74
+00:05:33,000 --> 00:05:38,000
+This is easy for you because you'll really understand what is happening under the hood will keep learning
+
+75
+00:05:38,000 --> 00:05:42,000
+new things and you need to understand how interactions happen.
+
+76
+00:05:43,000 --> 00:05:44,000
+What states threat has.
+
+77
+00:05:44,000 --> 00:05:50,000
+What demonstrates are how priorities, impacts, threats, cédula decisions and many other things.
+
+78
+00:05:51,000 --> 00:05:52,000
+You just need to understand this.
+
+79
+00:05:53,000 --> 00:05:54,000
+Let's move on.
+
+80
+00:05:54,000 --> 00:05:57,000
+Let me now explain what a colorful type is.
+
+81
+00:05:58,000 --> 00:06:05,000
+Callable is a functional interface that declare one method call pay attention that callable is a parametrized
+
+82
+00:06:05,000 --> 00:06:09,000
+type and call method returns value of a parametrized type.
+
+83
+00:06:09,000 --> 00:06:12,000
+Also call Massud Masroor exaction.
+
+84
+00:06:13,000 --> 00:06:17,000
+This is also important difference between call and run method from Runnable.
+
+85
+00:06:17,000 --> 00:06:24,000
+If you remember, one method returns Nassan and has a return type void and doesn't throw exception.
+
+86
+00:06:25,000 --> 00:06:29,000
+That's why we need to handle all checked exceptions inside our method.
+
+87
+00:06:30,000 --> 00:06:33,000
+But we can throw to upper level exception from call method.
+
+88
+00:06:34,000 --> 00:06:42,000
+Now I open killable demo, I create executor's service and to submit a task that has callable type we
+
+89
+00:06:42,000 --> 00:06:43,000
+have to call submit MassArt.
+
+90
+00:06:44,000 --> 00:06:51,000
+Execute method only takes Runnable but submit Massett is overloaded and the maitake is Akobo or animal.
+
+91
+00:06:52,000 --> 00:06:57,000
+In this case, with the lambda function I implement contract of killable interface.
+
+92
+00:06:57,000 --> 00:07:02,000
+If you are not familiar with lambda expressions, I recommend you to complete my functional programming
+
+93
+00:07:02,000 --> 00:07:03,000
+course for Java InGenius.
+
+94
+00:07:04,000 --> 00:07:06,000
+At the meantime we proceed.
+
+95
+00:07:06,000 --> 00:07:12,000
+So in this case, Corbel should return the value as a result of addition submit masjids returns as a
+
+96
+00:07:12,000 --> 00:07:14,000
+reference to the object of type future.
+
+97
+00:07:15,000 --> 00:07:18,000
+What is it the object of this type represents?
+
+98
+00:07:18,000 --> 00:07:25,000
+As a result of an asynchronous computation, methods are provided to check if the computation is complete,
+
+99
+00:07:25,000 --> 00:07:29,000
+to wait for its completion and to retrieve the result of the computation.
+
+100
+00:07:30,000 --> 00:07:32,000
+Let's review what methods we have here.
+
+101
+00:07:32,000 --> 00:07:38,000
+Cancel Masad was boolean flag the method attempts to cancel execution of this task.
+
+102
+00:07:39,000 --> 00:07:46,000
+This attempt will fail if the task has already completed, has already been cancelled or could not be
+
+103
+00:07:46,000 --> 00:07:47,000
+cancelled for some other reason.
+
+104
+00:07:48,000 --> 00:07:54,000
+Boolean flag here is to indicate whether we want to interrupt tasks that are in progress and is not
+
+105
+00:07:54,000 --> 00:07:55,000
+completed yet.
+
+106
+00:07:55,000 --> 00:07:58,000
+To achieve this, we need to pass true value here.
+
+107
+00:07:58,000 --> 00:08:01,000
+All we want to interrupt only tasks that are not started.
+
+108
+00:08:02,000 --> 00:08:05,000
+In this case, we need to pass false here is cancelled.
+
+109
+00:08:06,000 --> 00:08:09,000
+I believe that this a self-described method returns true.
+
+110
+00:08:09,000 --> 00:08:17,000
+If task has been canceled before it completes its normally and false otherwise is done returns true
+
+111
+00:08:17,000 --> 00:08:23,000
+if task was completed and false otherwise get this is a key method of future type in my opinion.
+
+112
+00:08:24,000 --> 00:08:30,000
+Pay attention to this method block threat of execution until computation of task will be completed.
+
+113
+00:08:30,000 --> 00:08:36,000
+That's why this massive Mercero interrupted exception in case Sarat will be interrupted while it waits
+
+114
+00:08:36,000 --> 00:08:43,000
+result of a task and potentially this massive miswrote execution exception in case some exceptional
+
+115
+00:08:43,000 --> 00:08:45,000
+happened during the task execution.
+
+116
+00:08:45,000 --> 00:08:51,000
+Yet method is overloaded and we have a great method that takes first a long argument and time unit.
+
+117
+00:08:51,000 --> 00:08:57,000
+I love this matter because it allows me to not look at constantly waiting for a result.
+
+118
+00:08:57,000 --> 00:09:04,000
+You can tell what the result of computation, for example, ten second and after that proceed with execution.
+
+119
+00:09:04,000 --> 00:09:07,000
+Additionally, this method maestro timeout exception.
+
+120
+00:09:07,000 --> 00:09:13,000
+If the wait time out, let's get back to our callable demo and proceed with our example.
+
+121
+00:09:13,000 --> 00:09:17,000
+Now I want to print the console result of task computation.
+
+122
+00:09:17,000 --> 00:09:19,000
+I call get massaged with time out.
+
+123
+00:09:20,000 --> 00:09:26,000
+Let me run this sap and in console I can see a result that was returned from the future object.
+
+124
+00:09:27,000 --> 00:09:32,000
+Can you understand now how killable works now when you know callable type.
+
+125
+00:09:32,000 --> 00:09:33,000
+Let's proceed.
+
+126
+00:09:33,000 --> 00:09:35,000
+Nolan executor services.
+
+127
+00:09:35,000 --> 00:09:40,000
+I'd like to review with you invoke all and invoke any assets and how they work.
+
+128
+00:09:40,000 --> 00:09:42,000
+I often invoke old demo file.
+
+129
+00:09:43,000 --> 00:09:45,000
+I create executor service.
+
+130
+00:09:45,000 --> 00:09:49,000
+After that I create a list of tasks I can use.
+
+131
+00:09:49,000 --> 00:09:56,000
+Executive service to submit multiple tasks at once in Roll Call has overloaded version with time out.
+
+132
+00:09:56,000 --> 00:10:03,000
+So this method may return results when all complete was a timeout expires which have a happy.
+
+133
+00:10:03,000 --> 00:10:11,000
+First invoke Oh, my throat interrupted exception, that's why you need to handle it or to let us know
+
+134
+00:10:11,000 --> 00:10:14,000
+that this piece of code, my throat interrupted the exception.
+
+135
+00:10:15,000 --> 00:10:19,000
+Let me run the program and I see you the results of each task.
+
+136
+00:10:20,000 --> 00:10:25,000
+Pay attention that invoke en masse, at least on future objects.
+
+137
+00:10:25,000 --> 00:10:29,000
+In our case, future is parametrized by strength.
+
+138
+00:10:29,000 --> 00:10:37,000
+I create a stream from this list and apply function to each future object that retrieves value from
+
+139
+00:10:37,000 --> 00:10:37,000
+it.
+
+140
+00:10:37,000 --> 00:10:40,000
+And I print all values to console.
+
+141
+00:10:40,000 --> 00:10:42,000
+Basically, that's it.
+
+142
+00:10:42,000 --> 00:10:47,000
+I believe you feel relieved that you don't need to create a new threat object for multiple tasks.
+
+143
+00:10:48,000 --> 00:10:54,000
+You don't need to start Masset on each thread, as you can see, starting multiple threads, much easier
+
+144
+00:10:54,000 --> 00:10:56,000
+with executive services.
+
+145
+00:10:56,000 --> 00:11:03,000
+The next example is in vogue and in demo is a precondition is similar to the one I had in invoke all
+
+146
+00:11:03,000 --> 00:11:03,000
+demo.
+
+147
+00:11:03,000 --> 00:11:05,000
+I have a little bit different tasks here.
+
+148
+00:11:06,000 --> 00:11:13,000
+Each task slips different amount of milliseconds and afterwards I call in WOAK animated on my executive
+
+149
+00:11:13,000 --> 00:11:14,000
+service.
+
+150
+00:11:14,000 --> 00:11:18,000
+I don't have list of features which can't return string value.
+
+151
+00:11:18,000 --> 00:11:22,000
+This is a result of completion of the task that was completed.
+
+152
+00:11:22,000 --> 00:11:29,000
+First, let me run the program and it doesn't matter how much I would run the sap, I would get the
+
+153
+00:11:29,000 --> 00:11:29,000
+same result.
+
+154
+00:11:30,000 --> 00:11:30,000
+Why?
+
+155
+00:11:31,000 --> 00:11:38,000
+Because the task number two has the shortest sleep time out and it will be always completed as the first
+
+156
+00:11:38,000 --> 00:11:38,000
+one.
+
+157
+00:11:39,000 --> 00:11:45,000
+This method also has overloaded version with time out in case time out will be over before any task
+
+158
+00:11:45,000 --> 00:11:46,000
+would be completed.
+
+159
+00:11:46,000 --> 00:11:49,000
+Timeout Exceptionable thrown in work.
+
+160
+00:11:49,000 --> 00:11:53,000
+Any Maestro interrupted exception and execution exception.
+
+161
+00:11:54,000 --> 00:11:58,000
+Execution exception will be thrown if no task successfully completes.
+
+162
+00:11:59,000 --> 00:11:59,000
+No.
+
+163
+00:11:59,000 --> 00:12:00,000
+Let's forget about this.
+
+164
+00:12:01,000 --> 00:12:03,000
+Now let me show you the next example.
+
+165
+00:12:03,000 --> 00:12:09,000
+I will show you how nice and elegant you might interrupt multiple threads, I hope an executive service
+
+166
+00:12:09,000 --> 00:12:11,000
+interruption demo file.
+
+167
+00:12:11,000 --> 00:12:13,000
+And here we have our next example.
+
+168
+00:12:14,000 --> 00:12:17,000
+I create executive service and submit different tasks.
+
+169
+00:12:17,000 --> 00:12:22,000
+Here I use extreme to generate stream of values from zero to nine.
+
+170
+00:12:22,000 --> 00:12:25,000
+And for each I perform the next operation.
+
+171
+00:12:25,000 --> 00:12:27,000
+I submit task for execution.
+
+172
+00:12:28,000 --> 00:12:30,000
+Does content sleep for time?
+
+173
+00:12:30,000 --> 00:12:31,000
+Out in seconds.
+
+174
+00:12:32,000 --> 00:12:32,000
+Pay attention.
+
+175
+00:12:32,000 --> 00:12:35,000
+That sleep interval is different in each task.
+
+176
+00:12:36,000 --> 00:12:39,000
+The longest sleep timeout is in the last.
+
+177
+00:12:39,000 --> 00:12:46,000
+And now when we submitted all tasks, let's focus on stress termination where we need to shut down our
+
+178
+00:12:46,000 --> 00:12:52,000
+executive service and executive service management, stress and process tasks there.
+
+179
+00:12:52,000 --> 00:12:54,000
+Any button case your app is finished.
+
+180
+00:12:54,000 --> 00:13:01,000
+You may still work because executive service will not be automatically destroyed and waiting.
+
+181
+00:13:01,000 --> 00:13:03,000
+Executive service may keep GBM running.
+
+182
+00:13:04,000 --> 00:13:10,000
+So how to close all threats that are managed by executive service, as a rule of thumb, is to follow
+
+183
+00:13:10,000 --> 00:13:12,000
+the next algorithm.
+
+184
+00:13:12,000 --> 00:13:17,000
+The first thing we need to do is to call shutdown method on executive service.
+
+185
+00:13:17,000 --> 00:13:22,000
+Shannon Mass makes executive service stop accepting new tasks and shut down.
+
+186
+00:13:22,000 --> 00:13:24,000
+After all, running tasks will be finished.
+
+187
+00:13:25,000 --> 00:13:31,000
+So theoretically you may just call shutdown method and let executive service finish its job.
+
+188
+00:13:31,000 --> 00:13:32,000
+And that's it.
+
+189
+00:13:32,000 --> 00:13:39,000
+In case you will try to submit any new task after we called shutdown method, you would get rejected
+
+190
+00:13:39,000 --> 00:13:42,000
+execution exception, source code of this example.
+
+191
+00:13:42,000 --> 00:13:48,000
+You may also find in attachments to this lesson and you can try to anchorman's this line and execute
+
+192
+00:13:48,000 --> 00:13:49,000
+an example.
+
+193
+00:13:49,000 --> 00:13:52,000
+You would have rejected the execution exception.
+
+194
+00:13:52,000 --> 00:13:56,000
+This is because I submit a task after a cold shutdown method.
+
+195
+00:13:57,000 --> 00:13:59,000
+We'll keep this line, command it for our example.
+
+196
+00:14:00,000 --> 00:14:01,000
+You can check this later.
+
+197
+00:14:01,000 --> 00:14:07,000
+If you don't trust me and you should never trust me, always verify everything by yourself, check documentation
+
+198
+00:14:07,000 --> 00:14:11,000
+and experiment with different code examples to understand the topic better.
+
+199
+00:14:12,000 --> 00:14:17,000
+After we called shutdown, it is recommended to use another method of termination.
+
+200
+00:14:18,000 --> 00:14:22,000
+This method takes longer value and time unit to define timeout.
+
+201
+00:14:22,000 --> 00:14:25,000
+How long we should wait for all tasks being completed.
+
+202
+00:14:26,000 --> 00:14:27,000
+Why we need this.
+
+203
+00:14:27,000 --> 00:14:32,000
+You already know potential issues of concurrent programs that look may happen.
+
+204
+00:14:32,000 --> 00:14:34,000
+A live look are probably some operation.
+
+205
+00:14:34,000 --> 00:14:40,000
+Just take significantly more time because of wait and the response from other server or something else.
+
+206
+00:14:41,000 --> 00:14:46,000
+But you don't want to keep your threats and tasks working if the time exceeds.
+
+207
+00:14:46,000 --> 00:14:53,000
+That's why we set specific time out for our executive service to finish all tasks, await termination.
+
+208
+00:14:53,000 --> 00:15:01,000
+Massata returns true in case Executer terminated and false is timeout elapsed before termination await
+
+209
+00:15:01,000 --> 00:15:03,000
+termination may throw in.
+
+210
+00:15:03,000 --> 00:15:09,000
+The rapid exception, because threat is waiting in this line for a specified amount of time and at this
+
+211
+00:15:09,000 --> 00:15:13,000
+moment, theoretically as a threat, may interrupt the current threat.
+
+212
+00:15:14,000 --> 00:15:18,000
+That's why Kampala makes us handle interrupted exception.
+
+213
+00:15:18,000 --> 00:15:25,000
+So we ask our executive service to wait for two seconds to complete all tasks and then finally block
+
+214
+00:15:25,000 --> 00:15:27,000
+I call shut down now MassArt.
+
+215
+00:15:28,000 --> 00:15:35,000
+This mass waits, nassan, and just attempts to stop all execution tasks and returns a list of tasks
+
+216
+00:15:35,000 --> 00:15:41,000
+that we are awaiting execution, we call it, to make sure that our executive service is terminated.
+
+217
+00:15:42,000 --> 00:15:43,000
+So let's review one more time.
+
+218
+00:15:44,000 --> 00:15:48,000
+We could shut down to stop accepting new tasks in our executive service.
+
+219
+00:15:49,000 --> 00:15:55,000
+Then we give time for executive service to complete all tasks and after that we try to interrupt all
+
+220
+00:15:55,000 --> 00:15:57,000
+tasks that are executed.
+
+221
+00:15:57,000 --> 00:16:01,000
+Let's run this program and investigate console output.
+
+222
+00:16:01,000 --> 00:16:03,000
+Shutting down text is printed.
+
+223
+00:16:03,000 --> 00:16:09,000
+After that, we managed to complete these tasks, but all of the threats were interrupted.
+
+224
+00:16:09,000 --> 00:16:17,000
+And you can see text from catch block that proves that all tasks terminated not instantly, but in places
+
+225
+00:16:17,000 --> 00:16:18,000
+where it is possible.
+
+226
+00:16:19,000 --> 00:16:22,000
+So tasks will be interrupted when threat is in a wait and state.
+
+227
+00:16:23,000 --> 00:16:27,000
+And you can handle interrupted exception according and logic of your program.
+
+228
+00:16:28,000 --> 00:16:30,000
+As I already said, shut down.
+
+229
+00:16:30,000 --> 00:16:33,000
+Now Massata returns the list of Runnable objects.
+
+230
+00:16:33,000 --> 00:16:37,000
+This is list of tasks that never come last execution.
+
+231
+00:16:38,000 --> 00:16:41,000
+Basically, that's what I wanted to share with you in this lesson.
+
+232
+00:16:42,000 --> 00:16:48,000
+We still need to learn executive service implementations, but I believe will have enough time in a
+
+233
+00:16:48,000 --> 00:16:48,000
+separate class.
+
+234
+00:16:48,000 --> 00:16:52,000
+And for that now let's review what we have learned in this lesson.
+
+235
+00:16:53,000 --> 00:16:55,000
+In this lesson, we learned executive interface.
+
+236
+00:16:56,000 --> 00:16:59,000
+Also, we learned another important interface, executive service.
+
+237
+00:17:00,000 --> 00:17:03,000
+After this lesson, you can understand what the threat is.
+
+238
+00:17:04,000 --> 00:17:10,000
+I explained what Corbel and future types are, and you saw how you can manage multiple threats with
+
+239
+00:17:10,000 --> 00:17:11,000
+executive service.
+
+240
+00:17:12,000 --> 00:17:17,000
+Now you know how to execute multiple tasks with the help of an OK all and invoke any methods.
+
+241
+00:17:18,000 --> 00:17:20,000
+And you know how to interrupt all tasks.
+
+242
+00:17:21,000 --> 00:17:22,000
+That's it for today.
+
+243
+00:17:22,000 --> 00:17:24,000
+Thanks a lot for your attention.
+
+244
+00:17:24,000 --> 00:17:26,000
+Have a great day and see you in the next lesson.
+
diff --git a/27 - Multithreading/007 Executor-Services-source-code-of-demo.url b/27 - Multithreading/007 Executor-Services-source-code-of-demo.url
new file mode 100644
index 0000000000000000000000000000000000000000..b7e6f4a8e938abd55bdd2ba297ba373bdb3a24e7
--- /dev/null
+++ b/27 - Multithreading/007 Executor-Services-source-code-of-demo.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/executors
\ No newline at end of file
diff --git a/27 - Multithreading/008 Executor Service Implementations & ThreadFactory_en.srt b/27 - Multithreading/008 Executor Service Implementations & ThreadFactory_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..987d009184ae89852eab21f4d8829259e68d58ea
--- /dev/null
+++ b/27 - Multithreading/008 Executor Service Implementations & ThreadFactory_en.srt
@@ -0,0 +1,1396 @@
+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.
+
diff --git a/27 - Multithreading/008 Executor-Service-Implementations-ThreadFactory-demo-source-code.url b/27 - Multithreading/008 Executor-Service-Implementations-ThreadFactory-demo-source-code.url
new file mode 100644
index 0000000000000000000000000000000000000000..b7e6f4a8e938abd55bdd2ba297ba373bdb3a24e7
--- /dev/null
+++ b/27 - Multithreading/008 Executor-Service-Implementations-ThreadFactory-demo-source-code.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/executors
\ No newline at end of file
diff --git a/27 - Multithreading/009 ForkJoin Framework_en.srt b/27 - Multithreading/009 ForkJoin Framework_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..547c48443c468182651e1c4003777622911ee9c6
--- /dev/null
+++ b/27 - Multithreading/009 ForkJoin Framework_en.srt
@@ -0,0 +1,940 @@
+1
+00:00:05,000 --> 00:00:10,000
+Hello there, students, in this lesson, we are going to learn with your fork join framework, we'll
+
+2
+00:00:10,000 --> 00:00:16,000
+start from the high level overview of your framework and understanding of its basic principles.
+
+3
+00:00:17,000 --> 00:00:20,000
+One will understand the theory of Forkin and Journey.
+
+4
+00:00:20,000 --> 00:00:24,000
+We would jump straight to the source code to learn first joint pool class.
+
+5
+00:00:24,000 --> 00:00:30,000
+I've explained what works to an algorithm is after that we are going to have practical code examples
+
+6
+00:00:30,000 --> 00:00:36,000
+and I will show you how to submit tasks for execution with the help of furniture and pool will review
+
+7
+00:00:36,000 --> 00:00:39,000
+recursive action and recursive type tasks.
+
+8
+00:00:40,000 --> 00:00:45,000
+And at the end of the lesson we are going to discuss drawbacks of Thorbjoern framework that we need
+
+9
+00:00:45,000 --> 00:00:49,000
+to be aware of for making a decision about its usage.
+
+10
+00:00:49,000 --> 00:00:53,000
+Let's start from understanding what Furbies during the framework is.
+
+11
+00:00:53,000 --> 00:00:56,000
+The first time it was presented in Java version seven.
+
+12
+00:00:57,000 --> 00:00:58,000
+Why it was needed.
+
+13
+00:00:58,000 --> 00:01:03,000
+The framework helps to speed up parallel processing by using all available course.
+
+14
+00:01:03,000 --> 00:01:08,000
+It is designed for work that can be broken into smaller pieces recursively.
+
+15
+00:01:09,000 --> 00:01:14,000
+The goal is to use all the available processing power to enhance the performance of your application.
+
+16
+00:01:15,000 --> 00:01:20,000
+Why it is called for joins and it is named after the way how it works.
+
+17
+00:01:20,000 --> 00:01:27,000
+The Framework X recursively breaking the task into smaller independent subtasks until they're simple
+
+18
+00:01:27,000 --> 00:01:29,000
+enough to be executed asynchronously.
+
+19
+00:01:30,000 --> 00:01:35,000
+And after that result of all subtasks, I recursively journey into a single result.
+
+20
+00:01:36,000 --> 00:01:37,000
+This is due in part.
+
+21
+00:01:38,000 --> 00:01:40,000
+That's why the framework is called for.
+
+22
+00:01:40,000 --> 00:01:42,000
+Join the Fork.
+
+23
+00:01:42,000 --> 00:01:45,000
+Join Framework distributes tasks to various threads in the thread.
+
+24
+00:01:45,000 --> 00:01:50,000
+Pull workers that are sleeping or waiting, not actually sleeping and waiting.
+
+25
+00:01:50,000 --> 00:01:57,000
+They're working on other smaller tasks for joint users work stealing algorithm workers.
+
+26
+00:01:57,000 --> 00:02:03,000
+Threads that run out of things to do can steal tasks from other threats that are still busy.
+
+27
+00:02:03,000 --> 00:02:08,000
+For example, doesn't create a separate thread for every single subtask.
+
+28
+00:02:08,000 --> 00:02:12,000
+Instead, each threatened ZAPU has its own double ended.
+
+29
+00:02:12,000 --> 00:02:15,000
+Q Modak, which stauss tasks.
+
+30
+00:02:16,000 --> 00:02:17,000
+Let's talk a little bit more about work.
+
+31
+00:02:17,000 --> 00:02:19,000
+Stulen algorithm.
+
+32
+00:02:19,000 --> 00:02:26,000
+If I could add a simple thread that if we try to steal work from decks of business threats by default,
+
+33
+00:02:26,000 --> 00:02:30,000
+every threat gets tasks from the head of its own deck.
+
+34
+00:02:30,000 --> 00:02:37,000
+When it is empty, the threat takes that task from the tail of the deck of another business threat or
+
+35
+00:02:37,000 --> 00:02:39,000
+from the global entry queue.
+
+36
+00:02:39,000 --> 00:02:45,000
+Since this is who has the biggest pieces of work are likely to be located today, we're going to review
+
+37
+00:02:45,000 --> 00:02:48,000
+a lot of JDK source code and code examples.
+
+38
+00:02:48,000 --> 00:02:50,000
+So let me start screen sharing.
+
+39
+00:02:51,000 --> 00:02:58,000
+The center of Fergin framework is, for example, Class I open source code of this class similar to
+
+40
+00:02:58,000 --> 00:02:59,000
+Oza Executor's.
+
+41
+00:02:59,000 --> 00:03:07,000
+It extends abasic executive service class that in turn implements executer service allsorts in the CPU
+
+42
+00:03:07,000 --> 00:03:14,000
+attempt to find and execute tasks submitted to the CPU and or created by other active tasks that that
+
+43
+00:03:15,000 --> 00:03:16,000
+a blocked or waiting.
+
+44
+00:03:16,000 --> 00:03:17,000
+At the moment.
+
+45
+00:03:17,000 --> 00:03:24,000
+This enables efficient processing when most tasks spawn other subtasks, as well as when many small
+
+46
+00:03:24,000 --> 00:03:27,000
+tasks are submitted to the CPU from external clients.
+
+47
+00:03:27,000 --> 00:03:29,000
+Let me open now.
+
+48
+00:03:29,000 --> 00:03:32,000
+For example, demo class I created IT.
+
+49
+00:03:32,000 --> 00:03:38,000
+Infrastructure and package done for you will be able to find the reference to the source code in attachments
+
+50
+00:03:38,000 --> 00:03:39,000
+to the lesson.
+
+51
+00:03:39,000 --> 00:03:42,000
+I am going to walk you through each line in this demo file.
+
+52
+00:03:43,000 --> 00:03:47,000
+The first thing that we do here is create an offer of joint pull object.
+
+53
+00:03:48,000 --> 00:03:50,000
+We can do this in different ways.
+
+54
+00:03:50,000 --> 00:03:53,000
+The first one is to use Static Masset Common Pool.
+
+55
+00:03:53,000 --> 00:03:56,000
+This will provide a reference to the common pool.
+
+56
+00:03:56,000 --> 00:04:03,000
+This pool and any ongoing process are automatically terminated upon program termination in case we'll
+
+57
+00:04:03,000 --> 00:04:05,000
+call X method of system class, for example.
+
+58
+00:04:06,000 --> 00:04:11,000
+Another way to create an instance of, for example, is just call upon the constructor.
+
+59
+00:04:11,000 --> 00:04:14,000
+The int parameter describes parallelism level.
+
+60
+00:04:14,000 --> 00:04:21,000
+This level indicates how many threads or CPUs you want to work concurrently on tasks past the function
+
+61
+00:04:21,000 --> 00:04:22,000
+pool.
+
+62
+00:04:22,000 --> 00:04:25,000
+In this case we have parallel is level of four.
+
+63
+00:04:26,000 --> 00:04:29,000
+We can create four adjourned without passing in value.
+
+64
+00:04:29,000 --> 00:04:35,000
+In this case, parallelism is equal to the end value that is returned by available processers.
+
+65
+00:04:35,000 --> 00:04:42,000
+Masset they remember in previous lesson I showed you a verbal processor that we can call on the runtime
+
+66
+00:04:42,000 --> 00:04:46,000
+object to define the number of processing, of course, we have on the machine.
+
+67
+00:04:47,000 --> 00:04:53,000
+Basically, if you don't have any specific reasons to set specific level of parallelism, you may use
+
+68
+00:04:53,000 --> 00:04:54,000
+default constructor.
+
+69
+00:04:54,000 --> 00:05:00,000
+Also, there is another constructor that allows it to pass to the constructor, sweat factory and error
+
+70
+00:05:00,000 --> 00:05:00,000
+handler.
+
+71
+00:05:01,000 --> 00:05:03,000
+Well, would you review similar example?
+
+72
+00:05:03,000 --> 00:05:09,000
+Also, sweat factory in previous lesson and another argument of type, unquote, exception handler is
+
+73
+00:05:09,000 --> 00:05:15,000
+a functional interface that requires you to implement logic of handling exceptional cases during the
+
+74
+00:05:15,000 --> 00:05:16,000
+execution.
+
+75
+00:05:16,000 --> 00:05:19,000
+It will depend on how you would like to address the exception.
+
+76
+00:05:20,000 --> 00:05:27,000
+Now we can proceed with submitting a task to our executer, similar to Oprah as examples with Runnable
+
+77
+00:05:27,000 --> 00:05:32,000
+and Kobel, we can submit two types of tasks actions and tasks.
+
+78
+00:05:32,000 --> 00:05:33,000
+Action.
+
+79
+00:05:33,000 --> 00:05:37,000
+This is something one doesn't return any value after execution.
+
+80
+00:05:37,000 --> 00:05:42,000
+Just set of instructions that needs to be executed in a separate sweat and task.
+
+81
+00:05:43,000 --> 00:05:47,000
+It is a type that will change the result of the execution similar to callable type.
+
+82
+00:05:48,000 --> 00:05:54,000
+Recursive action is a type that will not return as a result of the execution and objects of recursive
+
+83
+00:05:54,000 --> 00:05:56,000
+task type will return result of execution.
+
+84
+00:05:57,000 --> 00:06:03,000
+Most of them has an absolute mass compute in which the task logic is defined also.
+
+85
+00:06:03,000 --> 00:06:06,000
+Most of these types extends for the joint task.
+
+86
+00:06:06,000 --> 00:06:09,000
+Let's review examples with each of these types.
+
+87
+00:06:10,000 --> 00:06:15,000
+But before we jump to review code example, let me share a basic template for our tasks.
+
+88
+00:06:16,000 --> 00:06:16,000
+On the slide.
+
+89
+00:06:16,000 --> 00:06:18,000
+You can see pseudocode.
+
+90
+00:06:19,000 --> 00:06:27,000
+If my portion of the work is small enough, does it work directly or else split my work into two pieces
+
+91
+00:06:27,000 --> 00:06:30,000
+in one of the two pieces and wait for the results?
+
+92
+00:06:30,000 --> 00:06:33,000
+That is how we should implement compute method.
+
+93
+00:06:34,000 --> 00:06:39,000
+There should be some conditions that will tell us whether we can proceed with the execution directly
+
+94
+00:06:39,000 --> 00:06:40,000
+or we should create some.
+
+95
+00:06:41,000 --> 00:06:43,000
+Now let's look at the good example.
+
+96
+00:06:44,000 --> 00:06:50,000
+So as you may already understand, recursive action is just a set of instructions that are needed to
+
+97
+00:06:50,000 --> 00:06:50,000
+be done.
+
+98
+00:06:51,000 --> 00:06:57,000
+And recursive action may still need to break up its work into smaller chunks, which can be executed
+
+99
+00:06:57,000 --> 00:06:59,000
+by independent threads or CPU's.
+
+100
+00:07:00,000 --> 00:07:04,000
+Recursive action is an absolute class that extends for joint task.
+
+101
+00:07:04,000 --> 00:07:11,000
+So to create an object of this type, we need to have concrete implementation of this type in a separate
+
+102
+00:07:11,000 --> 00:07:16,000
+file of default recursive action clause that extends recursive action.
+
+103
+00:07:16,000 --> 00:07:22,000
+This is not a very meaningful example, but I decided to keep it super simple in order you would understand
+
+104
+00:07:22,000 --> 00:07:22,000
+how it works.
+
+105
+00:07:23,000 --> 00:07:26,000
+We have private in the field with named workload.
+
+106
+00:07:26,000 --> 00:07:32,000
+We would initialize it with some value during the default recursive action object instantiation.
+
+107
+00:07:32,000 --> 00:07:38,000
+And here is implementation of our compute method like you saw in template implementation.
+
+108
+00:07:38,000 --> 00:07:38,000
+On the slide.
+
+109
+00:07:39,000 --> 00:07:44,000
+We start with definition of a condition that should describe what we are going to proceed with.
+
+110
+00:07:44,000 --> 00:07:44,000
+Action.
+
+111
+00:07:44,000 --> 00:07:49,000
+Execution was a threat and one we should split our action into multiple subtasks.
+
+112
+00:07:50,000 --> 00:07:57,000
+In this case, we check if the workload value is less than 18, 18 in this case is a random threshold.
+
+113
+00:07:58,000 --> 00:08:05,000
+Just for the sake of example, when workload is less than 18, we just pursued action execution in the
+
+114
+00:08:05,000 --> 00:08:05,000
+same thread.
+
+115
+00:08:06,000 --> 00:08:13,000
+But in case it is equal to itchin or more, then we jump to our section where we create subtasks and
+
+116
+00:08:13,000 --> 00:08:14,000
+call for massive.
+
+117
+00:08:14,000 --> 00:08:19,000
+Here you can see two alternative ways how to achieve the same result.
+
+118
+00:08:19,000 --> 00:08:25,000
+We can create subtasks and call for method for each subtask like you can see in the foreach loop.
+
+119
+00:08:25,000 --> 00:08:33,000
+Or alternatively, we can use for a joint task class and call invoke all method and pass all subtasks
+
+120
+00:08:33,000 --> 00:08:35,000
+that the result would be the same.
+
+121
+00:08:36,000 --> 00:08:41,000
+I decided to keep for each loop here because the visualization is better in this case.
+
+122
+00:08:41,000 --> 00:08:46,000
+Let's understand how we create subtasks basically for our template.
+
+123
+00:08:46,000 --> 00:08:50,000
+We split my work into two pieces here.
+
+124
+00:08:50,000 --> 00:08:57,000
+You can see that I create two objects of the same action type and in constructor I pass workload divided
+
+125
+00:08:57,000 --> 00:08:57,000
+by two.
+
+126
+00:08:58,000 --> 00:09:02,000
+I add all subtasks to the release and return it from the method.
+
+127
+00:09:02,000 --> 00:09:09,000
+We use this list and for each loop or in invoke all Masset to submit this action for execution.
+
+128
+00:09:09,000 --> 00:09:11,000
+Let's get back to the, for example, demo class.
+
+129
+00:09:12,000 --> 00:09:18,000
+I just create an instance of my default recursive action and I pass it to the constructor.
+
+130
+00:09:18,000 --> 00:09:22,000
+I call invoke method and pass the reference to my action object.
+
+131
+00:09:23,000 --> 00:09:28,000
+Let's run this program and you can see that I split the workload and created two subtasks.
+
+132
+00:09:29,000 --> 00:09:34,000
+To sum it up, in your action task, you need to find a way to reflect the total amount of work.
+
+133
+00:09:35,000 --> 00:09:40,000
+Also, you need to define suitable thresholds that will be used to split action in subtasks.
+
+134
+00:09:40,000 --> 00:09:41,000
+Like another example.
+
+135
+00:09:41,000 --> 00:09:45,000
+This can be separate Masset that knows how to divide the work.
+
+136
+00:09:46,000 --> 00:09:51,000
+And in implementation of compute method, you should describe the conditions that would define what
+
+137
+00:09:51,000 --> 00:09:55,000
+it is time to split work into subtasks or proceed with execution.
+
+138
+00:09:56,000 --> 00:09:58,000
+Hope that it is clear.
+
+139
+00:09:58,000 --> 00:10:02,000
+Now let's look at the second type of tasks that we can submit into.
+
+140
+00:10:02,000 --> 00:10:10,000
+For example, now we are going to recursive task, recursive task is also APSA class that extends for
+
+141
+00:10:10,000 --> 00:10:11,000
+a joint task.
+
+142
+00:10:11,000 --> 00:10:16,000
+We want to submit a recursive task when we want to get the result of the calculation and the response.
+
+143
+00:10:16,000 --> 00:10:22,000
+The logic of interaction with objects of this type is similar was on the one difference.
+
+144
+00:10:22,000 --> 00:10:26,000
+We have to join the results of computation from different set tasks.
+
+145
+00:10:26,000 --> 00:10:33,000
+Let me open default recursive task class that extends recursive tasks and that implements compute method.
+
+146
+00:10:33,000 --> 00:10:39,000
+As you can see, we have similar constructor and the same field as we had in recursive action.
+
+147
+00:10:39,000 --> 00:10:46,000
+In case our condition tells us that we shouldn't split activity in different tasks, we just return
+
+148
+00:10:46,000 --> 00:10:46,000
+the result.
+
+149
+00:10:47,000 --> 00:10:52,000
+In this example, we just want to get values that twice the original value in the case.
+
+150
+00:10:52,000 --> 00:10:54,000
+We need to split our work into subtasks.
+
+151
+00:10:55,000 --> 00:11:00,000
+We do this, but also we need to join the results of all subtasks.
+
+152
+00:11:00,000 --> 00:11:06,000
+I call Gern Masset on each subtask that's supposed to return the result of computation.
+
+153
+00:11:06,000 --> 00:11:12,000
+I aggregate result in one variable and after that I return the result to them.
+
+154
+00:11:12,000 --> 00:11:15,000
+This case I have, for example, demo two class.
+
+155
+00:11:15,000 --> 00:11:20,000
+I create an instance of, for example, and call invoke method.
+
+156
+00:11:20,000 --> 00:11:25,000
+I pass an instance of the false recursive task with workload 40.
+
+157
+00:11:25,000 --> 00:11:28,000
+I run the program and Incans so output.
+
+158
+00:11:28,000 --> 00:11:31,000
+You can see that I get 80 as a result.
+
+159
+00:11:32,000 --> 00:11:34,000
+That is exactly what my task is supposed to do.
+
+160
+00:11:35,000 --> 00:11:35,000
+Great.
+
+161
+00:11:36,000 --> 00:11:39,000
+Is it clear for you how the recursive action and recursive task work?
+
+162
+00:11:40,000 --> 00:11:45,000
+If yes, then we are good to proceed in case the things that are still not clear.
+
+163
+00:11:45,000 --> 00:11:49,000
+Please leave your question under the switch and I will be happy to answer.
+
+164
+00:11:50,000 --> 00:11:56,000
+Now we are going to learn more about such factory method from executor's class as new for stealing pool
+
+165
+00:11:56,000 --> 00:11:56,000
+pull.
+
+166
+00:11:57,000 --> 00:12:04,000
+This method is overloaded and has versions within parameter and without parameters in the source code
+
+167
+00:12:04,000 --> 00:12:05,000
+of executor's class.
+
+168
+00:12:05,000 --> 00:12:11,000
+You can see that this is nothing more than, for example, instantiate that with a specific level of
+
+169
+00:12:11,000 --> 00:12:18,000
+parallelism or with the default level of parallelism that is equal to the number of available processors
+
+170
+00:12:18,000 --> 00:12:19,000
+and how to work with.
+
+171
+00:12:19,000 --> 00:12:25,000
+For example, you already know and we reviewed examples, I believe that you already understood potential
+
+172
+00:12:25,000 --> 00:12:32,000
+benefits that we expect to get from, for example, effective usage of all course, by splitting tasks
+
+173
+00:12:32,000 --> 00:12:35,000
+into subtasks, supposed to improve performance.
+
+174
+00:12:35,000 --> 00:12:38,000
+But we would help us in all cases.
+
+175
+00:12:38,000 --> 00:12:44,000
+Let's talk about disadvantages of, for example, probably after this lesson, you got an impression
+
+176
+00:12:44,000 --> 00:12:50,000
+that Fork Join framework is something extremely cool, efficient and super fast.
+
+177
+00:12:50,000 --> 00:12:54,000
+Probably even started to think that you have to use it.
+
+178
+00:12:54,000 --> 00:12:55,000
+Most often.
+
+179
+00:12:55,000 --> 00:12:59,000
+The evolution of Fergin pool vary between different engineers.
+
+180
+00:13:00,000 --> 00:13:03,000
+Not everyone agreed and shared benefits of this type.
+
+181
+00:13:04,000 --> 00:13:09,000
+If you would search the Internet pros and cons of, for example, you would discover that a group of
+
+182
+00:13:09,000 --> 00:13:15,000
+people who doesn't like, for example, because of different reasons on the slide, you can see the
+
+183
+00:13:15,000 --> 00:13:20,000
+list of the issues and drawbacks of, for example, based on different people opinion.
+
+184
+00:13:21,000 --> 00:13:25,000
+So it makes sense in some degree and in my opinion, worse to share with you.
+
+185
+00:13:26,000 --> 00:13:30,000
+So the drawbacks of, for example, are a faulty task manager.
+
+186
+00:13:31,000 --> 00:13:36,000
+The foraging technique splits the work into fragments and joins the results together.
+
+187
+00:13:37,000 --> 00:13:44,000
+And some practice that allows an intermediate joint for each fork can only work successfully in a controlled
+
+188
+00:13:44,000 --> 00:13:44,000
+environment.
+
+189
+00:13:45,000 --> 00:13:52,000
+A fatal flaw with Fergin framework by opinion of some group of people is that it is trying to manage
+
+190
+00:13:52,000 --> 00:13:53,000
+and intimidate.
+
+191
+00:13:53,000 --> 00:13:56,000
+Join in a task outside of a controlled environment.
+
+192
+00:13:56,000 --> 00:14:04,000
+Only the operating system as c the operating system can manage and intimidate join in the task and usually
+
+193
+00:14:04,000 --> 00:14:09,000
+there is a problem of errors, exceptions in subsequently FEG tasks.
+
+194
+00:14:09,000 --> 00:14:14,000
+And the answer to most of the cases that may happen in real life is uncertainty.
+
+195
+00:14:15,000 --> 00:14:21,000
+But this is not why people choose drama when we want to create robust application within the tools and
+
+196
+00:14:21,000 --> 00:14:23,000
+techniques to deal with uncertainties.
+
+197
+00:14:24,000 --> 00:14:31,000
+Inefficient, since all four tasks go into the same work as Red Deck, this team in various threads
+
+198
+00:14:31,000 --> 00:14:35,000
+will fight each other at the top of the deck over the four tasks.
+
+199
+00:14:36,000 --> 00:14:42,000
+This framework can never function efficiently in high performance environment, special purpose.
+
+200
+00:14:43,000 --> 00:14:46,000
+There are some restrictions to follow to make sure we can benefit from using.
+
+201
+00:14:46,000 --> 00:14:51,000
+For example, recommended restrictions must be plain.
+
+202
+00:14:51,000 --> 00:14:58,000
+That is mean between one hundred and ten thousand basic computational steps in the compute masset compute
+
+203
+00:14:58,000 --> 00:14:59,000
+intensive code only.
+
+204
+00:15:00,000 --> 00:15:02,000
+No blockin, no input.
+
+205
+00:15:02,000 --> 00:15:10,000
+Output, no synchronization, slow and unscalable, only works well on a small number of processors,
+
+206
+00:15:10,000 --> 00:15:14,000
+this design can never scale to hundreds or thousands of processors.
+
+207
+00:15:15,000 --> 00:15:23,000
+The overhead and reservation would nullify the benefits of additional processors exceedingly complex.
+
+208
+00:15:23,000 --> 00:15:26,000
+You can spend more time if you wish to investigate.
+
+209
+00:15:26,000 --> 00:15:32,000
+The source code of Thorbjoern framework was all Nasta types and how it is connected with the rest of
+
+210
+00:15:32,000 --> 00:15:34,000
+concurrent tools and JDK.
+
+211
+00:15:34,000 --> 00:15:41,000
+And you would agree that this is not the easiest and clear for understanding piece of JDK lacking in
+
+212
+00:15:41,000 --> 00:15:42,000
+professional attributes.
+
+213
+00:15:42,000 --> 00:15:48,000
+As a professional software engineer, as we always striving for excellence and following the best practices
+
+214
+00:15:48,000 --> 00:15:53,000
+some of them are, programs fail usually as a worst possible time.
+
+215
+00:15:53,000 --> 00:15:57,000
+Consequently, error recovery is paramount.
+
+216
+00:15:57,000 --> 00:16:00,000
+Software needs Deunan balancing of resources.
+
+217
+00:16:01,000 --> 00:16:08,000
+Administrators sometimes need classification, also called alerting logs and necessary.
+
+218
+00:16:08,000 --> 00:16:12,000
+The software should be useful across a wide range of computer needs.
+
+219
+00:16:13,000 --> 00:16:18,000
+The Fork Join Framework has none of this inadequate in scope.
+
+220
+00:16:18,000 --> 00:16:25,000
+The forging framework is only designed to work in a trivial segment of the computing world on Java standards
+
+221
+00:16:25,000 --> 00:16:28,000
+addition only on high performance workstations.
+
+222
+00:16:28,000 --> 00:16:36,000
+Six plus CPUs without high persuading do not compute, only work with no task input output, no Intertrust
+
+223
+00:16:36,000 --> 00:16:38,000
+concurrency and no networking.
+
+224
+00:16:39,000 --> 00:16:43,000
+So this is just some of the criticism against for of joint pool.
+
+225
+00:16:44,000 --> 00:16:48,000
+At the end of the day, it will be up to you how often and when to use it.
+
+226
+00:16:48,000 --> 00:16:52,000
+And now you have all necessary information to make this decision.
+
+227
+00:16:52,000 --> 00:16:55,000
+Let's recap what we have learned in this lesson.
+
+228
+00:16:55,000 --> 00:17:01,000
+In this lesson we learned what Fork Join framework is now, you know, the main masses of, for example,
+
+229
+00:17:01,000 --> 00:17:03,000
+class in the lesson.
+
+230
+00:17:03,000 --> 00:17:10,000
+We had some examples where the recursive action and recursive task, we executed these types of tasks
+
+231
+00:17:10,000 --> 00:17:12,000
+with the help of our gene pool.
+
+232
+00:17:12,000 --> 00:17:16,000
+And at the end of the lesson, we have discussed Fergin framework drawbacks.
+
+233
+00:17:17,000 --> 00:17:18,000
+That's it for this lesson.
+
+234
+00:17:18,000 --> 00:17:20,000
+Thanks a lot for your attention.
+
+235
+00:17:20,000 --> 00:17:23,000
+Have a great day and see you in the next lesson.
+
diff --git a/27 - Multithreading/009 Source-code-of-Fork-Join-examples.url b/27 - Multithreading/009 Source-code-of-Fork-Join-examples.url
new file mode 100644
index 0000000000000000000000000000000000000000..3ed12fb275893179cab8eae2e68187127af02683
--- /dev/null
+++ b/27 - Multithreading/009 Source-code-of-Fork-Join-examples.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/executors/forkjoin
\ No newline at end of file
diff --git a/27 - Multithreading/010 CompletableFuture-source-code-of-all-examples.url b/27 - Multithreading/010 CompletableFuture-source-code-of-all-examples.url
new file mode 100644
index 0000000000000000000000000000000000000000..27ed85726985d32e209926dcc5342acedb4c6011
--- /dev/null
+++ b/27 - Multithreading/010 CompletableFuture-source-code-of-all-examples.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/completablefuture
\ No newline at end of file
diff --git a/27 - Multithreading/010 CompletableFuture_en.srt b/27 - Multithreading/010 CompletableFuture_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..4de9500d5ebd68e4955cf7d236cf6893367ac061
--- /dev/null
+++ b/27 - Multithreading/010 CompletableFuture_en.srt
@@ -0,0 +1,1388 @@
+1
+00:00:05,000 --> 00:00:06,000
+Hello, dissidents.
+
+2
+00:00:06,000 --> 00:00:11,000
+Today, we are going to have a really interesting and useful lesson, we are going to learn how to work
+
+3
+00:00:11,000 --> 00:00:12,000
+with compatible future.
+
+4
+00:00:13,000 --> 00:00:18,000
+This is something what personally I use very often when I work with MultiThreaded and in my opinion,
+
+5
+00:00:18,000 --> 00:00:22,000
+this class and its features underestimated and on engineers.
+
+6
+00:00:22,000 --> 00:00:28,000
+So today I'm going to show you how powerful this type is and when we might use it.
+
+7
+00:00:28,000 --> 00:00:33,000
+We are going to learn how to execute tasks with comfortable future during the lesson will learn the
+
+8
+00:00:33,000 --> 00:00:39,000
+concept of the callback and how to work with callbacks with the help of compatible future.
+
+9
+00:00:39,000 --> 00:00:43,000
+Besides that, today we are going to learn more advanced concepts.
+
+10
+00:00:44,000 --> 00:00:49,000
+Namely, I'm going to show you how we can combine future objects together and work with them.
+
+11
+00:00:50,000 --> 00:00:55,000
+And at the end of the lesson, we learn how to manage exceptions in complete the future.
+
+12
+00:00:55,000 --> 00:01:00,000
+Let's start learning this topic with the help of official documentation and the source code.
+
+13
+00:01:00,000 --> 00:01:05,000
+Let's understand first what complete the future is and what problem it solves.
+
+14
+00:01:05,000 --> 00:01:11,000
+Creating multi spending programs is not an easy thing, especially it's hard to manage asynchronous
+
+15
+00:01:11,000 --> 00:01:14,000
+computations and build dependencies between those.
+
+16
+00:01:15,000 --> 00:01:21,000
+In case you have multiple steps in a program and each step may depend on execution of the previous step,
+
+17
+00:01:21,000 --> 00:01:27,000
+you try to find out ways how to implement this and code it may end up with having multiple callbacks
+
+18
+00:01:28,000 --> 00:01:30,000
+and logic may be scattered across the application.
+
+19
+00:01:31,000 --> 00:01:34,000
+And what about handlin errors that happened on one of the steps?
+
+20
+00:01:35,000 --> 00:01:37,000
+Should we handle the same error in different places?
+
+21
+00:01:37,000 --> 00:01:43,000
+Or we can find a way to create an exception handler for multiple connected steps during Lutece writing
+
+22
+00:01:43,000 --> 00:01:43,000
+processes.
+
+23
+00:01:44,000 --> 00:01:46,000
+Committable Future helps us to solve this issue.
+
+24
+00:01:46,000 --> 00:01:53,000
+And even more compatible future was released in Java Version eight to improve future interface.
+
+25
+00:01:53,000 --> 00:01:57,000
+Future Interface was released in Java Version five.
+
+26
+00:01:57,000 --> 00:02:03,000
+It was a great improvement, but its introduction doesn't solve an issue of connecting multiple tasks
+
+27
+00:02:03,000 --> 00:02:09,000
+between each other and API for error handling, along with future interface composable.
+
+28
+00:02:09,000 --> 00:02:14,000
+Future also implements another interface that was introduced in Java version eight.
+
+29
+00:02:15,000 --> 00:02:16,000
+It is called Completion Stage.
+
+30
+00:02:17,000 --> 00:02:19,000
+This time defines the context for behavior.
+
+31
+00:02:19,000 --> 00:02:26,000
+For an asynchronous computation step is that we combine with other steps in the source code of this
+
+32
+00:02:26,000 --> 00:02:28,000
+type and we find a lot of different methods.
+
+33
+00:02:28,000 --> 00:02:30,000
+Most of them are overloaded.
+
+34
+00:02:30,000 --> 00:02:37,000
+So implementation of completion, stage and future interfaces in complete the future gives us around
+
+35
+00:02:37,000 --> 00:02:43,000
+50 masses available to use those methods primarily for composing, combining, executing asynchronous
+
+36
+00:02:43,000 --> 00:02:45,000
+tasks and error handling.
+
+37
+00:02:46,000 --> 00:02:49,000
+Let's start watching compatible future code examples.
+
+38
+00:02:49,000 --> 00:02:53,000
+I create a separate package for examples only was complete the future.
+
+39
+00:02:53,000 --> 00:02:58,000
+I share the length of the package with you in attachments to this in the name No.
+
+40
+00:02:58,000 --> 00:03:03,000
+One, I'm going to show you the simplest and probably one of the most popular usage of compressible
+
+41
+00:03:03,000 --> 00:03:03,000
+future.
+
+42
+00:03:04,000 --> 00:03:07,000
+It is super easy to run asynchronous tasks with this type.
+
+43
+00:03:08,000 --> 00:03:14,000
+It has multiple static masses that allow us to execute task in a separate thread without long configuration
+
+44
+00:03:14,000 --> 00:03:19,000
+of a solid object or creation of executive service and shutting down it later in the case.
+
+45
+00:03:19,000 --> 00:03:22,000
+I just want to execute asynchronous task.
+
+46
+00:03:22,000 --> 00:03:25,000
+I just could run a static method of compostable feature class.
+
+47
+00:03:26,000 --> 00:03:26,000
+That's it.
+
+48
+00:03:27,000 --> 00:03:32,000
+For example, you just need to notify another service about work being started or done and you don't
+
+49
+00:03:32,000 --> 00:03:34,000
+care about response from the client.
+
+50
+00:03:35,000 --> 00:03:41,000
+Such a similar case cases may happen sometimes when you call around asking for joint command post is
+
+51
+00:03:41,000 --> 00:03:42,000
+used.
+
+52
+00:03:42,000 --> 00:03:49,000
+This approach is good for intensive and fast tasks, considering the fact when Java process is finished,
+
+53
+00:03:49,000 --> 00:03:50,000
+there is no common pool.
+
+54
+00:03:50,000 --> 00:03:56,000
+I put sleep here to let this thread be executed and bring this tax to consult run.
+
+55
+00:03:56,000 --> 00:03:58,000
+I think massive is overloaded.
+
+56
+00:03:58,000 --> 00:04:02,000
+There is a massive that takes Runnable object and executor as a method of argument.
+
+57
+00:04:03,000 --> 00:04:09,000
+In the next example here, I put the same lambda function for Runnable and Executive Service, considering
+
+58
+00:04:09,000 --> 00:04:16,000
+the fact that the second example here use a separate executive service and doesn't use for common pool,
+
+59
+00:04:16,000 --> 00:04:18,000
+I don't need to put any sleep here.
+
+60
+00:04:18,000 --> 00:04:19,000
+I'm not afraid.
+
+61
+00:04:19,000 --> 00:04:21,000
+Java process termination.
+
+62
+00:04:21,000 --> 00:04:27,000
+And you can see in console, thread, name and console output that imitates Sambrook that may be done
+
+63
+00:04:27,000 --> 00:04:30,000
+in a separate track by the thread name.
+
+64
+00:04:30,000 --> 00:04:34,000
+You can understand that surrounds is executed with the help of Fajon pull.
+
+65
+00:04:34,000 --> 00:04:39,000
+Make sure you watched my lesson about, for example, if you want them more about.
+
+66
+00:04:40,000 --> 00:04:43,000
+In the second case we use Red Bull executer.
+
+67
+00:04:43,000 --> 00:04:45,000
+That's why Swed name is different.
+
+68
+00:04:45,000 --> 00:04:46,000
+That's it.
+
+69
+00:04:46,000 --> 00:04:47,000
+We're getting this example.
+
+70
+00:04:47,000 --> 00:04:48,000
+Let's move on.
+
+71
+00:04:49,000 --> 00:04:55,000
+The next example is related was one of the features of computable future type you can complete task
+
+72
+00:04:55,000 --> 00:04:56,000
+was method.
+
+73
+00:04:56,000 --> 00:05:01,000
+To be honest, I have never used this method besides learning and educational purposes.
+
+74
+00:05:01,000 --> 00:05:07,000
+But this message is like one of the main sinks, incompatible future when you potentially need to use
+
+75
+00:05:07,000 --> 00:05:11,000
+it, let's say you need to fetch some data from another server.
+
+76
+00:05:11,000 --> 00:05:13,000
+Does this operation would take some time?
+
+77
+00:05:14,000 --> 00:05:17,000
+That's why you decided to run this task in a separate thread.
+
+78
+00:05:17,000 --> 00:05:22,000
+But something happened and the remote server doesn't respond for a specific amount of time.
+
+79
+00:05:23,000 --> 00:05:25,000
+And you really need to proceed with execution.
+
+80
+00:05:25,000 --> 00:05:29,000
+In this case, you may complete the future by returning the default value.
+
+81
+00:05:29,000 --> 00:05:34,000
+Let's look at the example I want to put into console result of a asynchronous calculation.
+
+82
+00:05:35,000 --> 00:05:38,000
+I call calculate calculator sink as it returns any future object.
+
+83
+00:05:39,000 --> 00:05:43,000
+And considering the fact that it's completed all the future implements future interface.
+
+84
+00:05:43,000 --> 00:05:46,000
+I can return composable future when needed.
+
+85
+00:05:46,000 --> 00:05:49,000
+I create an instance of complete double future.
+
+86
+00:05:49,000 --> 00:05:53,000
+After that I create cash, streetball and submit callable for execution.
+
+87
+00:05:54,000 --> 00:05:56,000
+I imitate a call to external server.
+
+88
+00:05:57,000 --> 00:06:02,000
+Imagine that I want to get some price double values that I will assign to the result variable and will
+
+89
+00:06:02,000 --> 00:06:05,000
+return it by making my sleep.
+
+90
+00:06:05,000 --> 00:06:08,000
+I imitate the delay in request a server.
+
+91
+00:06:09,000 --> 00:06:13,000
+After that I shut down executive service and I call a termination.
+
+92
+00:06:14,000 --> 00:06:18,000
+I am waiting for two seconds, only having the reference to the future object.
+
+93
+00:06:18,000 --> 00:06:22,000
+I can verify whether all calculations are done or not done.
+
+94
+00:06:23,000 --> 00:06:26,000
+If calculations are done, I return the reference to the future object.
+
+95
+00:06:27,000 --> 00:06:32,000
+If calculations are not done, I call complete Masset on my accomplishable future object and they pass
+
+96
+00:06:32,000 --> 00:06:35,000
+some default price values that I'm happy to return.
+
+97
+00:06:36,000 --> 00:06:43,000
+In this case, future won't be done and we are going to have force here because we await termination
+
+98
+00:06:43,000 --> 00:06:45,000
+only for two seconds.
+
+99
+00:06:45,000 --> 00:06:51,000
+But we expect tasks to be completed in five seconds after call and complete Masset completed.
+
+100
+00:06:51,000 --> 00:06:56,000
+All future will be considered as completed and I return the reference to the compatible future.
+
+101
+00:06:56,000 --> 00:07:02,000
+When I get the reference to the future, I just called Get MassArt and I extract complete result.
+
+102
+00:07:03,000 --> 00:07:08,000
+Let's run this program and you can see that in console we have nine point ninety nine.
+
+103
+00:07:08,000 --> 00:07:12,000
+This is our default price and we don't get new value.
+
+104
+00:07:12,000 --> 00:07:17,000
+Is it clear if no, ask question below this video and I will be happy to answer.
+
+105
+00:07:18,000 --> 00:07:20,000
+If everything is clear for you, then let's proceed.
+
+106
+00:07:21,000 --> 00:07:25,000
+The next example is located in the file was named Elmasry.
+
+107
+00:07:25,000 --> 00:07:27,000
+This time I'm going to show your supply.
+
+108
+00:07:27,000 --> 00:07:34,000
+I think similar to the run, I think said we can submit a task without boilerplate code.
+
+109
+00:07:35,000 --> 00:07:41,000
+But the only difference is that in releasing we passed Runnable object and here we need to pass supplier.
+
+110
+00:07:42,000 --> 00:07:47,000
+In case you're not familiar with supplier type, feel free to watch my course about functional programming
+
+111
+00:07:47,000 --> 00:07:48,000
+for Java engineers.
+
+112
+00:07:49,000 --> 00:07:55,000
+In that course, we have plenty of examples that will help you to understand a lot of functional interfaces,
+
+113
+00:07:55,000 --> 00:07:56,000
+including supply.
+
+114
+00:07:57,000 --> 00:07:58,000
+Basically, that's it.
+
+115
+00:07:59,000 --> 00:08:00,000
+Supply returns the value.
+
+116
+00:08:00,000 --> 00:08:07,000
+That's why I can get future after Colen supply, async and extract result from it.
+
+117
+00:08:07,000 --> 00:08:10,000
+Let's run this program and print result the console.
+
+118
+00:08:11,000 --> 00:08:17,000
+And as you can see in console, I managed to extract text from the future object and printed it to console.
+
+119
+00:08:17,000 --> 00:08:23,000
+So feel free to use this method in case you have something to execute in a separate thread and you need
+
+120
+00:08:23,000 --> 00:08:27,000
+to get the result of the execution hub that this example is clear.
+
+121
+00:08:28,000 --> 00:08:29,000
+Let's move on now.
+
+122
+00:08:29,000 --> 00:08:35,000
+We'll create with you a sequence of steps that should be executed one after another in a separate thread,
+
+123
+00:08:36,000 --> 00:08:42,000
+because it might happen that you need to perform another action based on the previous step completion.
+
+124
+00:08:42,000 --> 00:08:48,000
+So basically you can act complete about future, which should automatically get called once the future
+
+125
+00:08:48,000 --> 00:08:48,000
+completes.
+
+126
+00:08:49,000 --> 00:08:51,000
+Z is also often called a callback.
+
+127
+00:08:52,000 --> 00:08:55,000
+It is also known as call after function.
+
+128
+00:08:55,000 --> 00:09:00,000
+We have three methods that allow us to do this, then apply, then accept.
+
+129
+00:09:00,000 --> 00:09:04,000
+Xinran, we're going to review examples with these methods.
+
+130
+00:09:04,000 --> 00:09:11,000
+Now, let's start from then apply method in the file demo for I create super simple example to help
+
+131
+00:09:11,000 --> 00:09:13,000
+easily understand how this works.
+
+132
+00:09:13,000 --> 00:09:18,000
+The pardon is the same so you can apply it to any other tasks and calculations.
+
+133
+00:09:19,000 --> 00:09:26,000
+Imagine that you want to fetch user iji by email from one API and once you have user ID, you can request
+
+134
+00:09:26,000 --> 00:09:33,000
+total number of purchases for this user from another API and you need the result of first task execution
+
+135
+00:09:34,000 --> 00:09:41,000
+to get a D in order to be able to execute the second request I call supply asking to submit my first
+
+136
+00:09:41,000 --> 00:09:41,000
+task.
+
+137
+00:09:42,000 --> 00:09:49,000
+Is this a supplier that produces some result and after that I call then apply method and pass a function
+
+138
+00:09:49,000 --> 00:09:56,000
+that takes result of previous task execution as an input argument and that returns as a value.
+
+139
+00:09:56,000 --> 00:10:01,000
+I have console output in first and in second task just to imitate.
+
+140
+00:10:02,000 --> 00:10:08,000
+As a result of then applying, Masset is a future object that you can use to retrieve a result of computation
+
+141
+00:10:08,000 --> 00:10:15,000
+of the last step, you can build multiple steps like this, Michael, and then apply and to use in the
+
+142
+00:10:15,000 --> 00:10:20,000
+result of execution from previous step as an input argument for the next step.
+
+143
+00:10:20,000 --> 00:10:21,000
+Is that clear?
+
+144
+00:10:21,000 --> 00:10:23,000
+If yes, then great.
+
+145
+00:10:24,000 --> 00:10:27,000
+Also, there is another similar method then apply.
+
+146
+00:10:27,000 --> 00:10:27,000
+I think.
+
+147
+00:10:28,000 --> 00:10:30,000
+What would be the difference between then apply and then apply?
+
+148
+00:10:30,000 --> 00:10:38,000
+I think basically the main difference is the executor as it is used to execute these tasks by default,
+
+149
+00:10:38,000 --> 00:10:44,000
+then apply method uses the same threat that was used by the first task and uses the same exact as it
+
+150
+00:10:44,000 --> 00:10:48,000
+was defined by computable future on which it is called.
+
+151
+00:10:48,000 --> 00:10:52,000
+Then apply, I think uses independent executor by default.
+
+152
+00:10:53,000 --> 00:10:59,000
+It is forgery and common pool, but there is an overloaded method that allows it to pass executor service
+
+153
+00:11:00,000 --> 00:11:03,000
+like in the similar example below that will bring us to the same result.
+
+154
+00:11:04,000 --> 00:11:06,000
+I use executive service and then apply.
+
+155
+00:11:06,000 --> 00:11:12,000
+I think Massett in general, if you have multiple tasks for execution, I would just recommend it to
+
+156
+00:11:12,000 --> 00:11:18,000
+have executive service configured and use it for tasks execution that's triggered and then apply.
+
+157
+00:11:18,000 --> 00:11:20,000
+Masset, let's move on.
+
+158
+00:11:20,000 --> 00:11:22,000
+I open them a file file.
+
+159
+00:11:22,000 --> 00:11:28,000
+So as you already understood, then apply method returns to some future object.
+
+160
+00:11:28,000 --> 00:11:33,000
+But in case you don't want to create a return statement to return the result of the execution after
+
+161
+00:11:33,000 --> 00:11:40,000
+the final step and you just need to have some code got executed, you have to use it and accept us run.
+
+162
+00:11:41,000 --> 00:11:42,000
+We we're going to talk in a minute.
+
+163
+00:11:42,000 --> 00:11:44,000
+What is the difference between these two?
+
+164
+00:11:44,000 --> 00:11:46,000
+Let me just start explaining of that.
+
+165
+00:11:46,000 --> 00:11:53,000
+Except first, in this case, imagine that we need to extract full and complete user profile and in
+
+166
+00:11:53,000 --> 00:11:58,000
+the first step of this process, received text representation of user profile.
+
+167
+00:11:58,000 --> 00:12:05,000
+And after that, I just call then accept method to perform some operations that doesn't require me to
+
+168
+00:12:05,000 --> 00:12:06,000
+return the result.
+
+169
+00:12:06,000 --> 00:12:12,000
+For example, just saving this information somewhere in the application, probably in the user session
+
+170
+00:12:12,000 --> 00:12:18,000
+object or in local database, it doesn't matter, for example, then accept also returns compatible
+
+171
+00:12:18,000 --> 00:12:19,000
+future.
+
+172
+00:12:19,000 --> 00:12:23,000
+But this is compatible future that this parametrized by void type.
+
+173
+00:12:23,000 --> 00:12:29,000
+In case you would try to extract value from this future, you would get no, let's run this program.
+
+174
+00:12:30,000 --> 00:12:35,000
+And as you can see in console, I prefer that the console now so we can say that extract value from
+
+175
+00:12:35,000 --> 00:12:40,000
+the future after Colon's and accept doesn't make a lot of sense.
+
+176
+00:12:40,000 --> 00:12:46,000
+Similar to the previous example then, except MassArt has methods that allow to use separate executer
+
+177
+00:12:46,000 --> 00:12:52,000
+for each step, then accept async Macit use a separate executer for tasks execution.
+
+178
+00:12:52,000 --> 00:12:53,000
+Is it clear?
+
+179
+00:12:54,000 --> 00:12:59,000
+Now let's look at the next example with Iran Masset and understand how it is different.
+
+180
+00:13:00,000 --> 00:13:07,000
+I open domestiques, almost similar example, but in this case I just want to see user profile to another
+
+181
+00:13:07,000 --> 00:13:07,000
+server.
+
+182
+00:13:08,000 --> 00:13:13,000
+And once this task will be executed, I want to look that user profile has been saved, but perform
+
+183
+00:13:13,000 --> 00:13:15,000
+any other actions after the first one.
+
+184
+00:13:16,000 --> 00:13:22,000
+In this case, there is no need for me to call supply async because the result of computation of the
+
+185
+00:13:22,000 --> 00:13:25,000
+first step will not be passed to anywhere.
+
+186
+00:13:25,000 --> 00:13:31,000
+That's why it wouldn't matter at all what value will be returned from the first step of the execution.
+
+187
+00:13:31,000 --> 00:13:38,000
+And after it I just called and run method to perform some actions in this case just to notify the user.
+
+188
+00:13:38,000 --> 00:13:44,000
+Profile has been saved and I can proceed with other operations that were dependent on the first one.
+
+189
+00:13:45,000 --> 00:13:50,000
+And again, we are future objects rechanneled, but it contains nothing in response.
+
+190
+00:13:50,000 --> 00:13:54,000
+And also we have similar Massata then run, which is called Zinda Run.
+
+191
+00:13:54,000 --> 00:14:01,000
+I think this method will use separate executive service either for example or the ones at the specified
+
+192
+00:14:02,000 --> 00:14:05,000
+hope that you understand now how to work with these matters.
+
+193
+00:14:05,000 --> 00:14:06,000
+Let's continue.
+
+194
+00:14:07,000 --> 00:14:10,000
+I'd like to talk about a combination of different future objects.
+
+195
+00:14:11,000 --> 00:14:12,000
+I open them.
+
+196
+00:14:12,000 --> 00:14:18,000
+A seven file imagines that you already have two masses and both of them return complete the future object.
+
+197
+00:14:19,000 --> 00:14:27,000
+The first method extracts user details by ID and the second method extracts credit rating by user details.
+
+198
+00:14:27,000 --> 00:14:30,000
+You already know how to use and apply MassArt.
+
+199
+00:14:30,000 --> 00:14:36,000
+Let's look how it would look like in this case when you would call one method and after that you would
+
+200
+00:14:36,000 --> 00:14:42,000
+call another method that also the Transcom political future you would get as a result compatible future.
+
+201
+00:14:42,000 --> 00:14:44,000
+That is parametrized by compatible future.
+
+202
+00:14:45,000 --> 00:14:47,000
+It is not too convenient to work with the result.
+
+203
+00:14:47,000 --> 00:14:54,000
+Now you should call get method twice to extract the results that you wanted, especially for such cases.
+
+204
+00:14:54,000 --> 00:14:58,000
+There is a composed method in case I call them compose.
+
+205
+00:14:58,000 --> 00:15:00,000
+Instead of apply, I get complete.
+
+206
+00:15:01,000 --> 00:15:03,000
+Future parametrized by the time of my results.
+
+207
+00:15:04,000 --> 00:15:05,000
+And that's it.
+
+208
+00:15:05,000 --> 00:15:11,000
+This solution is more elegant in case you want to compose one future object out of two.
+
+209
+00:15:11,000 --> 00:15:19,000
+If in those three Mapai in Java, I am sure you remember that there is such as flat map, that mass,
+
+210
+00:15:19,000 --> 00:15:20,000
+it is similar to this one.
+
+211
+00:15:21,000 --> 00:15:26,000
+So you can extract completely a future from another conceivable future and get flat representation of
+
+212
+00:15:26,000 --> 00:15:27,000
+the result.
+
+213
+00:15:27,000 --> 00:15:31,000
+Also in this case, we have one task running after another.
+
+214
+00:15:31,000 --> 00:15:33,000
+So two dependent tasks.
+
+215
+00:15:33,000 --> 00:15:37,000
+We have also similar methods that are called then compose a scene.
+
+216
+00:15:37,000 --> 00:15:39,000
+I believe you already understand.
+
+217
+00:15:39,000 --> 00:15:41,000
+What is the difference then?
+
+218
+00:15:41,000 --> 00:15:43,000
+Compose a scene you separate.
+
+219
+00:15:43,000 --> 00:15:49,000
+Executer let me open them are eight now in the case, two tasks are independent and you just want to
+
+220
+00:15:49,000 --> 00:15:53,000
+complete two of them in any order you can call them combine.
+
+221
+00:15:53,000 --> 00:15:58,000
+In this case you can perform some actions after two tasks are completed.
+
+222
+00:15:58,000 --> 00:16:02,000
+So again, we have to masset that return complete double future.
+
+223
+00:16:02,000 --> 00:16:06,000
+One method returns weight and another method which is height.
+
+224
+00:16:07,000 --> 00:16:10,000
+Each massive sleep for one second inside.
+
+225
+00:16:10,000 --> 00:16:17,000
+This is just to imitate some operation time in the main mass that we get weight in KG future, and after
+
+226
+00:16:17,000 --> 00:16:22,000
+that we call them combined Masset and we pass height in centimeters future.
+
+227
+00:16:22,000 --> 00:16:29,000
+That together with my function, as you remember, my function can take two arguments and returns.
+
+228
+00:16:29,000 --> 00:16:34,000
+The result, these two arguments would be the result of these two future objects.
+
+229
+00:16:34,000 --> 00:16:39,000
+And once we get the result, we apply the function inside the BI function.
+
+230
+00:16:39,000 --> 00:16:44,000
+I want to calculate the body mass index by following a specific formula here.
+
+231
+00:16:44,000 --> 00:16:51,000
+Let's run the program and you can see in concert that after and weight and height I start calculating
+
+232
+00:16:51,000 --> 00:16:52,000
+body mass index.
+
+233
+00:16:53,000 --> 00:16:58,000
+And the main thing here is that I don't need to have connection between execution of the first and the
+
+234
+00:16:58,000 --> 00:17:02,000
+second task that can be executed in parallel.
+
+235
+00:17:02,000 --> 00:17:05,000
+But I just need the result of both computations.
+
+236
+00:17:06,000 --> 00:17:12,000
+And for the convention, we have then combined async method, which is overloaded and has a version
+
+237
+00:17:12,000 --> 00:17:16,000
+that was default executer and was a separate executer argument.
+
+238
+00:17:16,000 --> 00:17:20,000
+I open them online file and you already know that.
+
+239
+00:17:20,000 --> 00:17:25,000
+Then combined, MassArt returns the result of computation of the future objects.
+
+240
+00:17:25,000 --> 00:17:32,000
+We have another method that is called Xanax, Sambo's, that instead of by function takes by consumer,
+
+241
+00:17:32,000 --> 00:17:40,000
+that means it doesn't return any value and just consumes the results of execution of two tasks and works
+
+242
+00:17:40,000 --> 00:17:42,000
+with two future objects and return nothing.
+
+243
+00:17:43,000 --> 00:17:47,000
+So in this case, you can see that I supply lambda expressions.
+
+244
+00:17:47,000 --> 00:17:48,000
+It returns first.
+
+245
+00:17:48,000 --> 00:17:53,000
+I call accept the both and after that I supply lambda expressions.
+
+246
+00:17:53,000 --> 00:17:57,000
+It returns the second and we just bring concatenated string to consult.
+
+247
+00:17:58,000 --> 00:18:04,000
+And in case I would extract the value from the future object, I would get no because then accept the
+
+248
+00:18:04,000 --> 00:18:05,000
+most massive returns.
+
+249
+00:18:05,000 --> 00:18:08,000
+Computable future parametrized by voit type.
+
+250
+00:18:09,000 --> 00:18:16,000
+Lets run the program and you can see that I printed concatenated string the new value proofs that my
+
+251
+00:18:16,000 --> 00:18:17,000
+future contains.
+
+252
+00:18:17,000 --> 00:18:21,000
+Nassan also we have similar MassArt foreign conventions.
+
+253
+00:18:21,000 --> 00:18:24,000
+We have then accept both async method.
+
+254
+00:18:24,000 --> 00:18:30,000
+So far I've learned math that allowed us to combine only to complete the future objects.
+
+255
+00:18:31,000 --> 00:18:36,000
+Now we are going to land mass that allow us to combine multiple completive of future objects.
+
+256
+00:18:37,000 --> 00:18:45,000
+There are two masses of and any of both of these masses accept variable arguments of political future
+
+257
+00:18:45,000 --> 00:18:45,000
+type.
+
+258
+00:18:45,000 --> 00:18:47,000
+Let's review these two.
+
+259
+00:18:47,000 --> 00:18:50,000
+I open them more than we have here.
+
+260
+00:18:50,000 --> 00:18:52,000
+Simple, but a very interesting example.
+
+261
+00:18:53,000 --> 00:18:57,000
+We are going to come up with a few more masses that I didn't share with you before.
+
+262
+00:18:57,000 --> 00:19:03,000
+The goal of this example is to create a list of strings and turn them into a capital case.
+
+263
+00:19:03,000 --> 00:19:04,000
+Pretty simple scenario.
+
+264
+00:19:04,000 --> 00:19:11,000
+And we will solve this task with computable future, not because I love complicated things, but just
+
+265
+00:19:11,000 --> 00:19:15,000
+to help you understand this example, I create a list of strings.
+
+266
+00:19:15,000 --> 00:19:22,000
+After that, I create a string from this list I call Map Masset and passing functions that completed
+
+267
+00:19:22,000 --> 00:19:27,000
+the future method returns and you complete the future object as it is already completed with the given
+
+268
+00:19:27,000 --> 00:19:28,000
+value.
+
+269
+00:19:28,000 --> 00:19:36,000
+After that, I then apply Masset for each string and invoke the late uppercase Delate uppercase sleep
+
+270
+00:19:36,000 --> 00:19:43,000
+for a random amount of time, but up to one second and returns the current string in uppercase.
+
+271
+00:19:44,000 --> 00:19:50,000
+This random sleep imitates operation time in case there will be more actions here.
+
+272
+00:19:50,000 --> 00:19:57,000
+After that, we have a list of future objects I call all of Masset and POS array of future objects,
+
+273
+00:19:57,000 --> 00:20:00,000
+considering the fact that all of Masad may accept.
+
+274
+00:20:00,000 --> 00:20:07,000
+The verbal argument, all of matter will reach a new political future that is completed when all of
+
+275
+00:20:07,000 --> 00:20:10,000
+the give and complete futures complete.
+
+276
+00:20:10,000 --> 00:20:17,000
+But what would happen in case one of the given futures complete, exceptionally Zenzi complete political
+
+277
+00:20:17,000 --> 00:20:24,000
+future also does so as a result, if any of the given political futures are not reflected in the return
+
+278
+00:20:24,000 --> 00:20:29,000
+to complete the future, but may be obtained by inspecting them individually.
+
+279
+00:20:30,000 --> 00:20:33,000
+After that, I call one complete MassArt.
+
+280
+00:20:33,000 --> 00:20:40,000
+This message returns and you completion stage with the same result of exception as the stage and executes
+
+281
+00:20:40,000 --> 00:20:41,000
+that given action.
+
+282
+00:20:41,000 --> 00:20:49,000
+When this stage completes one complete takes by consumer as method argument in this by consumer receives
+
+283
+00:20:49,000 --> 00:20:56,000
+the result on now if none and the exception on now if none of the stages arguments to get the results,
+
+284
+00:20:56,000 --> 00:21:00,000
+we need to go over our features one more time.
+
+285
+00:21:00,000 --> 00:21:07,000
+In this case, I just print each updated string to console pay attention that I could get now masset
+
+286
+00:21:07,000 --> 00:21:08,000
+of complete double future.
+
+287
+00:21:09,000 --> 00:21:11,000
+We didn't discuss this method yet.
+
+288
+00:21:11,000 --> 00:21:18,000
+Get now returns the value if computation is finished and returns default values that we pass as a method
+
+289
+00:21:18,000 --> 00:21:20,000
+argument if result is not ready.
+
+290
+00:21:20,000 --> 00:21:23,000
+In our case we use one complete Macit.
+
+291
+00:21:23,000 --> 00:21:28,000
+So we assume that all of the features were done by this moment in our program.
+
+292
+00:21:28,000 --> 00:21:32,000
+So I print all uppercase string to consult.
+
+293
+00:21:32,000 --> 00:21:33,000
+Let me run this program.
+
+294
+00:21:34,000 --> 00:21:35,000
+That's it.
+
+295
+00:21:36,000 --> 00:21:43,000
+Any questions regarding all of Masset leaves them under review in case of any the next them is related
+
+296
+00:21:43,000 --> 00:21:44,000
+to any of method.
+
+297
+00:21:45,000 --> 00:21:47,000
+Let me open them on file here.
+
+298
+00:21:47,000 --> 00:21:51,000
+We have absolutely similar example, but with only one difference.
+
+299
+00:21:52,000 --> 00:21:59,000
+Instead of all of I call any of method here any of Masset returns and you completed all future that
+
+300
+00:21:59,000 --> 00:22:04,000
+is completed when any of the given completed will future complete.
+
+301
+00:22:04,000 --> 00:22:10,000
+So in this case, the first future that will be completed will be printed to cancel.
+
+302
+00:22:10,000 --> 00:22:16,000
+Let me run this program that it I have been processed first and that's it.
+
+303
+00:22:17,000 --> 00:22:19,000
+Nothing else is printed to consult.
+
+304
+00:22:19,000 --> 00:22:20,000
+Does it make sense?
+
+305
+00:22:20,000 --> 00:22:21,000
+Great.
+
+306
+00:22:21,000 --> 00:22:22,000
+Let's proceed.
+
+307
+00:22:23,000 --> 00:22:28,000
+And the last, but not least for today, I am going to show you how to handle exceptions with the help
+
+308
+00:22:28,000 --> 00:22:29,000
+of compatible future.
+
+309
+00:22:30,000 --> 00:22:35,000
+This type allows us to handle errors in a chain of asynchronous computation steps.
+
+310
+00:22:36,000 --> 00:22:41,000
+Instead of having to try catch block, we have handle Masset that receives two arguments.
+
+311
+00:22:41,000 --> 00:22:47,000
+The first one is a result of computation in case all processing was finished successfully, and the
+
+312
+00:22:47,000 --> 00:22:52,000
+second argument is exceptions thrown in case there was some exceptional case.
+
+313
+00:22:52,000 --> 00:22:58,000
+I open them Otwell file in this file we have examples of error handling I supply.
+
+314
+00:22:58,000 --> 00:23:05,000
+I think the next task I have int variables that is equal to five and I divided by zero.
+
+315
+00:23:06,000 --> 00:23:09,000
+We're going to have error if we take exception in this line.
+
+316
+00:23:09,000 --> 00:23:12,000
+But take into account this is a onetime exception.
+
+317
+00:23:12,000 --> 00:23:19,000
+Compiler doesn't warn us about potential Hanlan, but I'm smart enough to handle Masad after the last
+
+318
+00:23:19,000 --> 00:23:19,000
+step.
+
+319
+00:23:19,000 --> 00:23:23,000
+And by the way, you may have multiple steps handle.
+
+320
+00:23:23,000 --> 00:23:28,000
+Masset will catch exception on any step of execution in case there are no exceptions.
+
+321
+00:23:29,000 --> 00:23:35,000
+Result of execution would be in the first argument and in case a recent exception, I have the reference
+
+322
+00:23:35,000 --> 00:23:40,000
+to the exception object passed as a second argument that surrounds this program.
+
+323
+00:23:41,000 --> 00:23:44,000
+And in console output we can see that we enter this.
+
+324
+00:23:44,000 --> 00:23:52,000
+If LOC I printed the class of the exception, it is completion exception and it is caused by arithmetic
+
+325
+00:23:52,000 --> 00:23:52,000
+exception.
+
+326
+00:23:53,000 --> 00:23:57,000
+So we can see how a completion exception is the regional exception.
+
+327
+00:23:57,000 --> 00:23:59,000
+We have also another method for error.
+
+328
+00:23:59,000 --> 00:24:00,000
+Hanlan.
+
+329
+00:24:00,000 --> 00:24:02,000
+It is called exceptionally.
+
+330
+00:24:02,000 --> 00:24:09,000
+The difference is that it takes not by function like handle matter, but it takes function and has parameter
+
+331
+00:24:09,000 --> 00:24:16,000
+of Straubel type is the same way I check exception here and considering the fact that I don't have any
+
+332
+00:24:16,000 --> 00:24:19,000
+result available, I can return some default value, for example.
+
+333
+00:24:20,000 --> 00:24:21,000
+That's it.
+
+334
+00:24:21,000 --> 00:24:23,000
+We learned a lot about the future.
+
+335
+00:24:24,000 --> 00:24:29,000
+In case there is anything else you want to know about compatible future, please ask questions.
+
+336
+00:24:29,000 --> 00:24:36,000
+Now let's recap what we have learned in this lesson, in this lesson we learned complete about future.
+
+337
+00:24:36,000 --> 00:24:42,000
+As I said in the beginning of the lesson, it is very useful class that I use very often when I work
+
+338
+00:24:42,000 --> 00:24:46,000
+with multithreaded, it helps to solve a lot of pain points.
+
+339
+00:24:46,000 --> 00:24:52,000
+We learned different methods that describes how to execute tasks was complete the future also.
+
+340
+00:24:52,000 --> 00:24:56,000
+Now you know what a callback is and how to work with callbacks.
+
+341
+00:24:56,000 --> 00:25:00,000
+With the help of compatible future thought, we managed to build multiple.
+
+342
+00:25:00,000 --> 00:25:07,000
+Step with this writing process and real examples, you saw how we can combine future objects and work
+
+343
+00:25:07,000 --> 00:25:13,000
+with them, and at the end of the lesson, I explained how we can manage exceptions with complete double
+
+344
+00:25:13,000 --> 00:25:13,000
+future time.
+
+345
+00:25:14,000 --> 00:25:15,000
+That's all for this lesson.
+
+346
+00:25:16,000 --> 00:25:17,000
+Thanks a lot for your attention.
+
+347
+00:25:17,000 --> 00:25:20,000
+Have a great day and see you in the next lesson.
+
diff --git a/27 - Multithreading/011 Lock API - Lock, ReadWriteLock, ReentrantLock, ReentrantReadWriteLock, StampedLo_en.srt b/27 - Multithreading/011 Lock API - Lock, ReadWriteLock, ReentrantLock, ReentrantReadWriteLock, StampedLo_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..01f1db078fd1cbc4a1ea78ab53f1ddd60b28acc3
--- /dev/null
+++ b/27 - Multithreading/011 Lock API - Lock, ReadWriteLock, ReentrantLock, ReentrantReadWriteLock, StampedLo_en.srt
@@ -0,0 +1,1868 @@
+1
+00:00:05,000 --> 00:00:10,000
+Hello, adjustments, students, in this lesson, we're going to learn new tools for synchronization
+
+2
+00:00:10,000 --> 00:00:11,000
+of access to critical sections.
+
+3
+00:00:12,000 --> 00:00:14,000
+We're going to learn log API.
+
+4
+00:00:14,000 --> 00:00:21,000
+We'll start from general overview of what API, what advantages it has over synchronize blocks and when
+
+5
+00:00:21,000 --> 00:00:21,000
+we need to use it.
+
+6
+00:00:22,000 --> 00:00:28,000
+I will provide you with detailed comparative analysis what we have in API and what we don't have in
+
+7
+00:00:28,000 --> 00:00:31,000
+synchronized masses and synchronize blocks.
+
+8
+00:00:31,000 --> 00:00:37,000
+This will help you to understand better what problems like API intended to solve in the last.
+
+9
+00:00:37,000 --> 00:00:44,000
+And we'll discuss such important interfaces as Locke and with Right Look, once we learned interfaces
+
+10
+00:00:44,000 --> 00:00:50,000
+will jump to concrete implementations and will learn with you today, resentence slok or Interent,
+
+11
+00:00:50,000 --> 00:00:52,000
+read the right look and stamped log.
+
+12
+00:00:53,000 --> 00:00:59,000
+We are going to have a lot of examples and I will show you how to use low conditions and achieve fairness
+
+13
+00:00:59,000 --> 00:01:00,000
+with respect to weight and threats.
+
+14
+00:01:01,000 --> 00:01:07,000
+Let's start and as usual, before diving into the details, let's try to understand what problems look
+
+15
+00:01:07,000 --> 00:01:14,000
+API supposed to solve and how it is different from synchronized masses and synchronized blocks like
+
+16
+00:01:14,000 --> 00:01:21,000
+implementations provide more extensive looking operations than can be obtained using synchronized methods
+
+17
+00:01:21,000 --> 00:01:23,000
+and statements they allow.
+
+18
+00:01:23,000 --> 00:01:30,000
+More flexible structuring may have quite different properties and may support multiple associated condition
+
+19
+00:01:30,000 --> 00:01:30,000
+objects.
+
+20
+00:01:31,000 --> 00:01:35,000
+The first time log API was introduced in Java version five.
+
+21
+00:01:35,000 --> 00:01:42,000
+To put it simple, it is easy to explain why we might want to use look API sometimes and how it is different
+
+22
+00:01:42,000 --> 00:01:48,000
+from synchronized keywords through the discussion of look API advantages and comparison with synchronize
+
+23
+00:01:48,000 --> 00:01:49,000
+blocks.
+
+24
+00:01:50,000 --> 00:01:53,000
+Look may be obtained and released in different places.
+
+25
+00:01:53,000 --> 00:01:58,000
+For example, you may acquire a lock in one method and release log and other A when needed.
+
+26
+00:01:59,000 --> 00:02:05,000
+This is something that you can't do with synchronized block because all block should be located in one
+
+27
+00:02:05,000 --> 00:02:09,000
+single method time limit talk dialogue to avoid deadlocks.
+
+28
+00:02:09,000 --> 00:02:11,000
+The remember deadlock example.
+
+29
+00:02:11,000 --> 00:02:16,000
+That is something that may never happen if only we use all features of the API.
+
+30
+00:02:16,000 --> 00:02:22,000
+There is a specific behavior in place that allows us to try to acquire a log for a specific interval
+
+31
+00:02:22,000 --> 00:02:26,000
+of time in case log is not acquired.
+
+32
+00:02:26,000 --> 00:02:32,000
+We built our logic in the way where we just proceed with other activities to not wait for log infinite
+
+33
+00:02:32,000 --> 00:02:36,000
+amount of time and come into the deadlock state work with conditions.
+
+34
+00:02:37,000 --> 00:02:38,000
+What are conditions?
+
+35
+00:02:39,000 --> 00:02:45,000
+Condition is a separate type that provides the ability for a thread to wait for some condition to occur
+
+36
+00:02:45,000 --> 00:02:48,000
+while executing the critical section.
+
+37
+00:02:49,000 --> 00:02:50,000
+Why we might need this.
+
+38
+00:02:50,000 --> 00:02:56,000
+This can occur when a threat acquires the access to the critical section, but doesn't have the necessary
+
+39
+00:02:56,000 --> 00:02:58,000
+condition to perform its operation.
+
+40
+00:02:59,000 --> 00:03:05,000
+For example, a reader threat can get access to the log of a shared Q, which still doesn't have any
+
+41
+00:03:05,000 --> 00:03:06,000
+data to consume.
+
+42
+00:03:07,000 --> 00:03:14,000
+Traditionally, Java provides weight Latifi and notify all methods for threat intercommunication conditions
+
+43
+00:03:14,000 --> 00:03:22,000
+have similar mechanism, but in addition, we can specify multiple conditions and the advantage of log
+
+44
+00:03:22,000 --> 00:03:25,000
+API is a furnace for threats that are waiting for work.
+
+45
+00:03:25,000 --> 00:03:27,000
+Long hours and hours of threats.
+
+46
+00:03:27,000 --> 00:03:34,000
+We can't achieve fairness in synchronized blocks because each threat may capture look once it is released.
+
+47
+00:03:35,000 --> 00:03:40,000
+But in lock API we can achieve fairness by specifying the fairness property.
+
+48
+00:03:41,000 --> 00:03:46,000
+It makes sure that the longest wait in threat is given access to the lock also.
+
+49
+00:03:46,000 --> 00:03:50,000
+And K Street is waiting for monitors to enter synchronized block.
+
+50
+00:03:50,000 --> 00:03:52,000
+It cannot be interrupted.
+
+51
+00:03:52,000 --> 00:03:57,000
+Lock API allows us to interrupt sarap when it's waiting for the lock.
+
+52
+00:03:57,000 --> 00:04:04,000
+Basically, these are both advantages of lock API and the main difference is a different looks from
+
+53
+00:04:04,000 --> 00:04:09,000
+synchronize blocks and believes that you already understood that knowing how to work with this API,
+
+54
+00:04:09,000 --> 00:04:14,000
+you would be able to create more robust multithreaded application with higher performance.
+
+55
+00:04:15,000 --> 00:04:17,000
+I can confirm that personally.
+
+56
+00:04:17,000 --> 00:04:23,000
+I ask about KPI at least few questions during the interview, but probably not all interviewers do so.
+
+57
+00:04:24,000 --> 00:04:30,000
+And also not all candidates, unfortunately, can explain why we need to look API and what is more important,
+
+58
+00:04:30,000 --> 00:04:31,000
+how to use it.
+
+59
+00:04:32,000 --> 00:04:36,000
+In this lesson, we are going to learn how to work with API by examples.
+
+60
+00:04:36,000 --> 00:04:43,000
+So probably it is a good time for me to start a screenshot and learn with your API by examples.
+
+61
+00:04:43,000 --> 00:04:48,000
+Before we jump to good examples, let's look at the source code of interface.
+
+62
+00:04:48,000 --> 00:04:51,000
+Lock interface declares six masses.
+
+63
+00:04:51,000 --> 00:04:52,000
+We are going to use this now.
+
+64
+00:04:53,000 --> 00:04:56,000
+The first method in this list is look very simple.
+
+65
+00:04:56,000 --> 00:04:58,000
+It requires a lock in.
+
+66
+00:04:58,000 --> 00:05:02,000
+The lock is not available and already acquired by another thread.
+
+67
+00:05:02,000 --> 00:05:05,000
+The current threat waiting until the lock will be acquired.
+
+68
+00:05:06,000 --> 00:05:10,000
+This is similar to capturing, monitoring, synchronized Masset and unsynchronized blocks.
+
+69
+00:05:11,000 --> 00:05:18,000
+The next message that I'd like to review with you is unlock this massive releases a look at a similar
+
+70
+00:05:18,000 --> 00:05:19,000
+US live and synchronized blog.
+
+71
+00:05:20,000 --> 00:05:25,000
+But as you already understand, and more flexible with locks rather than with synchronize blocks, I
+
+72
+00:05:25,000 --> 00:05:29,000
+can release look in the scope of the massive if this is needed.
+
+73
+00:05:29,000 --> 00:05:34,000
+Also, we have message that allows us to acquire look only if that's free.
+
+74
+00:05:34,000 --> 00:05:36,000
+I am talking about Trialogue Masset.
+
+75
+00:05:37,000 --> 00:05:39,000
+Also this message retransplant value.
+
+76
+00:05:39,000 --> 00:05:42,000
+It returns true if Lokke has been acquired and false.
+
+77
+00:05:42,000 --> 00:05:45,000
+Otherwise, nothing special.
+
+78
+00:05:45,000 --> 00:05:51,000
+You can just build your logic around this method to make sure you execute alternative steps in case
+
+79
+00:05:51,000 --> 00:05:53,000
+law can't be acquired.
+
+80
+00:05:53,000 --> 00:05:56,000
+And the next one, probably my favorite one try.
+
+81
+00:05:56,000 --> 00:06:03,000
+Look, with time constraints, probably because of this method looks become so popular.
+
+82
+00:06:03,000 --> 00:06:08,000
+Well, definitely not only because of this method, but I really believe that this method is something
+
+83
+00:06:08,000 --> 00:06:15,000
+that what was needed to adjudicate so long time before Java Version five release it is similar to the
+
+84
+00:06:15,000 --> 00:06:17,000
+previous one was one difference.
+
+85
+00:06:17,000 --> 00:06:23,000
+You try to acquire LOC within the specified amount of time and in case time is elapsed, you proceed
+
+86
+00:06:23,000 --> 00:06:25,000
+with alternative steps.
+
+87
+00:06:25,000 --> 00:06:31,000
+This method allows it to wait for specific time and after that procedure execution, this will help
+
+88
+00:06:31,000 --> 00:06:37,000
+us to avoid deadlocks and at the same time acquire a lock in case it was released after some period
+
+89
+00:06:37,000 --> 00:06:37,000
+of time.
+
+90
+00:06:38,000 --> 00:06:43,000
+Looking to rapidly, MassArt was partially discussed already when we talked about advantages.
+
+91
+00:06:44,000 --> 00:06:51,000
+This is similar to the lock method, but it allows the blocks to be interrupted and resume's execution
+
+92
+00:06:51,000 --> 00:06:53,000
+through a strong interactive exception.
+
+93
+00:06:53,000 --> 00:06:56,000
+And the last method in this list is new condition.
+
+94
+00:06:57,000 --> 00:06:59,000
+We are going to talk about it also later today.
+
+95
+00:06:59,000 --> 00:07:05,000
+And it would be easier for you to understand this method was example, but in short, you can declare
+
+96
+00:07:05,000 --> 00:07:09,000
+lock conditions that will help you to coordinate work between multiple threats.
+
+97
+00:07:10,000 --> 00:07:16,000
+So as you can see, this interface has different methods that allows us to support a certain level of
+
+98
+00:07:16,000 --> 00:07:20,000
+flexibility during the development of just training programs.
+
+99
+00:07:20,000 --> 00:07:24,000
+But this comes with the requirement to know how to use this API.
+
+100
+00:07:24,000 --> 00:07:24,000
+Agree.
+
+101
+00:07:25,000 --> 00:07:27,000
+We already reviewed log interface.
+
+102
+00:07:28,000 --> 00:07:34,000
+Now it is Tantallon implementations and look at the examples that will help us to understand each specific
+
+103
+00:07:34,000 --> 00:07:36,000
+method and how it works.
+
+104
+00:07:36,000 --> 00:07:42,000
+And one of the most popular direct implementation of the interface is a reinforcement law class.
+
+105
+00:07:42,000 --> 00:07:46,000
+That's why our first class today is called reinforcement log demo.
+
+106
+00:07:47,000 --> 00:07:52,000
+The first thing that I do here, I declare a static count variables that will be implemented concurrently
+
+107
+00:07:52,000 --> 00:07:53,000
+by different threads.
+
+108
+00:07:54,000 --> 00:07:56,000
+This is going to be my shared resource.
+
+109
+00:07:56,000 --> 00:08:03,000
+After that, I declare our field of logotype and initialize it with the object of reinterred logotype.
+
+110
+00:08:03,000 --> 00:08:09,000
+After that, I have the same example that our shared with you when we started on synchronization for
+
+111
+00:08:09,000 --> 00:08:10,000
+the very first time.
+
+112
+00:08:10,000 --> 00:08:14,000
+The remember example with comes as it is implemented from two threads.
+
+113
+00:08:15,000 --> 00:08:21,000
+Here we have the same example, but instead of synchronized masad or synchronized log, we are going
+
+114
+00:08:21,000 --> 00:08:22,000
+to use log object.
+
+115
+00:08:23,000 --> 00:08:26,000
+Let me quickly remind you, what do we have here in my method?
+
+116
+00:08:27,000 --> 00:08:32,000
+But before we start explanation of what is written below, it is must that you watched the previous
+
+117
+00:08:32,000 --> 00:08:36,000
+lessons, especially about synchronization and synchronized blocks.
+
+118
+00:08:37,000 --> 00:08:39,000
+In this example, I would refer to that one.
+
+119
+00:08:39,000 --> 00:08:42,000
+And they need to be able to compare these two examples.
+
+120
+00:08:43,000 --> 00:08:48,000
+And also, if you are not familiar with functional interfaces and functional style of coding and Java,
+
+121
+00:08:48,000 --> 00:08:52,000
+please watch my functional programming course for Java developers.
+
+122
+00:08:52,000 --> 00:08:54,000
+Now let's proceed.
+
+123
+00:08:54,000 --> 00:08:59,000
+I create the instance of the current class to be able to invoke non static masses.
+
+124
+00:08:59,000 --> 00:09:06,000
+With the help of this reference, I create executive service that I'm going to use to execute all tasks
+
+125
+00:09:06,000 --> 00:09:07,000
+in this line.
+
+126
+00:09:07,000 --> 00:09:15,000
+I execute tense tasks I use in stream object to generate range from zero and collusively to ten thousand
+
+127
+00:09:15,000 --> 00:09:16,000
+exclusively.
+
+128
+00:09:16,000 --> 00:09:22,000
+And after that I call for each method to execute task with my executive service.
+
+129
+00:09:22,000 --> 00:09:28,000
+On each iteration, I pass the reference to the message that means the contract of Runnable interface.
+
+130
+00:09:29,000 --> 00:09:35,000
+Considering the Trinamool is a functional interface, I can pass that reference here so each task will
+
+131
+00:09:35,000 --> 00:09:39,000
+increment Cowens variable, but pay attention to the implementation.
+
+132
+00:09:39,000 --> 00:09:48,000
+I kolok method on my log object to acquire LOC after this method invocation only once read will be able
+
+133
+00:09:48,000 --> 00:09:53,000
+to execute next lines concurrently and to make sure that I would release log.
+
+134
+00:09:53,000 --> 00:10:01,000
+The rule of thumb is to invoke and lock MassArt in final and block Y because theoretically some exception
+
+135
+00:10:01,000 --> 00:10:02,000
+may happen.
+
+136
+00:10:02,000 --> 00:10:09,000
+Between lock and unlock and vacation and the unwelcome assets in this case won't be executed and in
+
+137
+00:10:09,000 --> 00:10:15,000
+this case we would never release lock and all other threats would wait for an infinite amount of time
+
+138
+00:10:15,000 --> 00:10:16,000
+until Lokke will be released.
+
+139
+00:10:16,000 --> 00:10:19,000
+And until then, we will be in a deadlock state.
+
+140
+00:10:19,000 --> 00:10:20,000
+Definitely.
+
+141
+00:10:20,000 --> 00:10:26,000
+It is hard to imagine that some exceptionals happened after incremented, but still it is a rule of
+
+142
+00:10:26,000 --> 00:10:26,000
+thumb.
+
+143
+00:10:26,000 --> 00:10:33,000
+And then when you start to create this habit and look, Masset is involved in finitely block to make
+
+144
+00:10:33,000 --> 00:10:36,000
+sure that I would release log one hundred percent.
+
+145
+00:10:36,000 --> 00:10:40,000
+So this is a task that I'm going to execute ten thousand times.
+
+146
+00:10:40,000 --> 00:10:47,000
+After all of this, I shut down my executive service and wait in maximum for three seconds until all
+
+147
+00:10:47,000 --> 00:10:51,000
+tasks complete and print result of count of verbal to console.
+
+148
+00:10:52,000 --> 00:10:58,000
+Let's run this program and I'm going to run this program multiple times to prove that the counter is
+
+149
+00:10:58,000 --> 00:10:59,000
+always equal to ten thousand.
+
+150
+00:11:00,000 --> 00:11:04,000
+And we don't have the last update in this specific case.
+
+151
+00:11:04,000 --> 00:11:09,000
+This massive increment was luck is similar to this one with synchronized lock.
+
+152
+00:11:09,000 --> 00:11:13,000
+If you can't understand why, then we need to use the lock.
+
+153
+00:11:13,000 --> 00:11:17,000
+Please refer to the slight advantages of lock API.
+
+154
+00:11:17,000 --> 00:11:21,000
+It is less likely that you would use the API for such simple example.
+
+155
+00:11:22,000 --> 00:11:29,000
+Most likely you're going to use more complicated solution where you would need API and also I doubt
+
+156
+00:11:29,000 --> 00:11:31,000
+that you would use just lock.
+
+157
+00:11:31,000 --> 00:11:36,000
+MassArt most likely are going to use Trialogue with timeout or trying to raptly.
+
+158
+00:11:36,000 --> 00:11:37,000
+Is that clear?
+
+159
+00:11:38,000 --> 00:11:39,000
+If yes, let's press it.
+
+160
+00:11:40,000 --> 00:11:47,000
+So why is this lock is called reentries lock a lock is called reinterred in the thread that holds the
+
+161
+00:11:47,000 --> 00:11:55,000
+lock can lock it again and non interent lock is a lock which cannot be locked again if it is locked.
+
+162
+00:11:55,000 --> 00:11:58,000
+Not even by the thread that holds the lock.
+
+163
+00:11:59,000 --> 00:12:05,000
+Nonagenarians locks may result in very interesting lock out, which is the situation similar to a deadlock.
+
+164
+00:12:05,000 --> 00:12:12,000
+So I hope that from the name of the class it is clear that the arrangement lock class is arranger's
+
+165
+00:12:12,000 --> 00:12:13,000
+lock.
+
+166
+00:12:13,000 --> 00:12:19,000
+That means that even if a thread holds in the lock, it can acquire it again.
+
+167
+00:12:19,000 --> 00:12:26,000
+Consequently, this thread must unlock it as many times as it has locked it in order to fully unlock
+
+168
+00:12:26,000 --> 00:12:28,000
+the reinforcement log for other threats.
+
+169
+00:12:29,000 --> 00:12:30,000
+Let's now review example.
+
+170
+00:12:30,000 --> 00:12:35,000
+When we interent, Lock acquires the same lock multiple times for the same threat.
+
+171
+00:12:35,000 --> 00:12:38,000
+I open arrangement, lock them up to file.
+
+172
+00:12:39,000 --> 00:12:41,000
+I create an object of reinterred lock first.
+
+173
+00:12:41,000 --> 00:12:48,000
+The goal of this demo is to hold such operations as addition and subtraction with two operands only
+
+174
+00:12:48,000 --> 00:12:55,000
+in the main masset accurate an object of this -- class because I need to use it to go non static marcedes.
+
+175
+00:12:56,000 --> 00:13:02,000
+I create executer service that I'm going to use to execute my calculation operations in different threads.
+
+176
+00:13:02,000 --> 00:13:06,000
+I have calculated massive here that holds absolute logic.
+
+177
+00:13:07,000 --> 00:13:07,000
+Let's look at it.
+
+178
+00:13:08,000 --> 00:13:10,000
+The method takes three arguments.
+
+179
+00:13:10,000 --> 00:13:16,000
+The first one is operator is a plus, an ominous sign and two operands for operation.
+
+180
+00:13:17,000 --> 00:13:21,000
+Based on the operator I execute is a at method, a subtract.
+
+181
+00:13:22,000 --> 00:13:23,000
+But the main thing is following.
+
+182
+00:13:24,000 --> 00:13:30,000
+I call Lock Masset when I just enter calculate method and I call lock method again.
+
+183
+00:13:30,000 --> 00:13:32,000
+When I enter is an add or subtract.
+
+184
+00:13:33,000 --> 00:13:35,000
+So I call log method two times.
+
+185
+00:13:36,000 --> 00:13:38,000
+This is called retention clock.
+
+186
+00:13:38,000 --> 00:13:39,000
+The same threat.
+
+187
+00:13:39,000 --> 00:13:42,000
+McQuire the same lock multiple times.
+
+188
+00:13:42,000 --> 00:13:43,000
+Definitely.
+
+189
+00:13:43,000 --> 00:13:49,000
+We need to call unwelcome MassArt twice now to make sure that our lock is completely released and as
+
+190
+00:13:49,000 --> 00:13:51,000
+a threat might acquire a lock.
+
+191
+00:13:51,000 --> 00:13:59,000
+That's why I have finally locks was unlock massive location in, add and subtract methods and in calculate
+
+192
+00:13:59,000 --> 00:14:04,000
+method to pay attention that after each lock and unlock matters I lock massaged to console.
+
+193
+00:14:05,000 --> 00:14:09,000
+This will help us to investigate what is happening inside the sap.
+
+194
+00:14:09,000 --> 00:14:17,000
+Let's run this program and in console output we can see the same pattern Loki's acquired two times.
+
+195
+00:14:17,000 --> 00:14:22,000
+That is output from calculate and from either add or subtract methods.
+
+196
+00:14:22,000 --> 00:14:25,000
+And after that we have lock is released two times.
+
+197
+00:14:26,000 --> 00:14:33,000
+That means that only once threat acquiring and releasing logs and only after log is released and Nasrat
+
+198
+00:14:33,000 --> 00:14:39,000
+acquire and release logs and so on, and the result of computation are correct.
+
+199
+00:14:39,000 --> 00:14:40,000
+Is that clear?
+
+200
+00:14:41,000 --> 00:14:44,000
+Can you understand now what this really interent lock means?
+
+201
+00:14:44,000 --> 00:14:49,000
+In case you have any questions, please do not hesitate to write your questions below this here.
+
+202
+00:14:50,000 --> 00:14:50,000
+Let's move on.
+
+203
+00:14:51,000 --> 00:14:57,000
+As I said in the beginning of our lesson, when we discussed advantages of lock API, we can ensure
+
+204
+00:14:57,000 --> 00:14:59,000
+fair order of threats.
+
+205
+00:14:59,000 --> 00:15:01,000
+Talk why lock what is fair and.
+
+206
+00:15:03,000 --> 00:15:06,000
+Imagine that you have 10 threats that are waiting to acquire a lock.
+
+207
+00:15:07,000 --> 00:15:12,000
+Some of them waiting more and some of them just arrived in the queue and not waiting so long.
+
+208
+00:15:13,000 --> 00:15:19,000
+So not very long doesn't guarantee the order in which threats wait and talk, wires lock.
+
+209
+00:15:19,000 --> 00:15:25,000
+And this might bring us to this reservation state once sweat will wait for lock access forever.
+
+210
+00:15:26,000 --> 00:15:30,000
+So does reinterred lock fair or unfair law by default?
+
+211
+00:15:30,000 --> 00:15:34,000
+This isn't fair, but we can make it fair.
+
+212
+00:15:34,000 --> 00:15:36,000
+Let us know how to do this.
+
+213
+00:15:36,000 --> 00:15:39,000
+I open the source code of interest law.
+
+214
+00:15:39,000 --> 00:15:46,000
+Plus there is a specific constructor in reinjuring law that takes boolean parameters specifying whether
+
+215
+00:15:46,000 --> 00:15:48,000
+the range of law should be fair or no.
+
+216
+00:15:49,000 --> 00:15:55,000
+So just calls are constructed and pass through value here to enable fairness for all wait and threats.
+
+217
+00:15:56,000 --> 00:15:56,000
+Is it.
+
+218
+00:15:57,000 --> 00:16:00,000
+So now let's review how we look with time, how it works.
+
+219
+00:16:01,000 --> 00:16:03,000
+I open reinjuring them three.
+
+220
+00:16:03,000 --> 00:16:06,000
+I have for instance, created on the class level.
+
+221
+00:16:07,000 --> 00:16:12,000
+I create executive service that has two threats only and they want to execute two tasks.
+
+222
+00:16:13,000 --> 00:16:19,000
+I use Masset reference to refer to the massive inside this clause that describes the logic that should
+
+223
+00:16:19,000 --> 00:16:21,000
+be executed in a separate thread.
+
+224
+00:16:22,000 --> 00:16:29,000
+I try to gweilo during the two seconds in case laughers acquired my task will sleep for three seconds.
+
+225
+00:16:29,000 --> 00:16:31,000
+Is that especially for demo purposes?
+
+226
+00:16:32,000 --> 00:16:37,000
+Because when frustrated with the dialogue, the second threat would wait here for two seconds, only
+
+227
+00:16:37,000 --> 00:16:39,000
+trying to acquire a look.
+
+228
+00:16:39,000 --> 00:16:41,000
+But I would get false here.
+
+229
+00:16:41,000 --> 00:16:48,000
+And the second threat would execute alternative actions because law wasn't acquired within the time
+
+230
+00:16:48,000 --> 00:16:48,000
+specified.
+
+231
+00:16:49,000 --> 00:16:55,000
+Here is a blog to handle potential interrupts the exception that might be thrown while threat will be
+
+232
+00:16:55,000 --> 00:16:56,000
+sleeping.
+
+233
+00:16:56,000 --> 00:16:59,000
+And finally, block here is to unlock the lock.
+
+234
+00:16:59,000 --> 00:17:02,000
+Let's run this program in console output.
+
+235
+00:17:02,000 --> 00:17:09,000
+We can see that first threat managed to acquire a lock and enter Eve block and while FirstRand asleep
+
+236
+00:17:09,000 --> 00:17:16,000
+and for three seconds the second threat tries to acquire the lock in the two seconds and after that
+
+237
+00:17:16,000 --> 00:17:18,000
+we sickle-cell output from Ellsburg.
+
+238
+00:17:19,000 --> 00:17:22,000
+Basically that is how try and lock with time outworks.
+
+239
+00:17:23,000 --> 00:17:23,000
+Let's continue.
+
+240
+00:17:24,000 --> 00:17:26,000
+Let's learn now how to work with conditions.
+
+241
+00:17:27,000 --> 00:17:29,000
+What is the condition to condition.
+
+242
+00:17:29,000 --> 00:17:37,000
+Interface provides the ability to suspend its execution until the given conditions through a condition
+
+243
+00:17:37,000 --> 00:17:39,000
+object is necessarily bound to lock.
+
+244
+00:17:40,000 --> 00:17:45,000
+They remember how we worked with wait, notify and notify all methods we have.
+
+245
+00:17:45,000 --> 00:17:47,000
+Similar thing here was condition.
+
+246
+00:17:48,000 --> 00:17:52,000
+The idea is the same, but the way how it is implemented is different.
+
+247
+00:17:53,000 --> 00:17:57,000
+Also, you may have multiple conditions attached to the one lock.
+
+248
+00:17:57,000 --> 00:18:04,000
+The condition is important to be verified by a thread when it tries to access the critical section,
+
+249
+00:18:04,000 --> 00:18:07,000
+but doesn't meet specific conditions to proceed with the execution.
+
+250
+00:18:08,000 --> 00:18:14,000
+The simplest example is when the reader thread got access to the log of the shared Q But that still
+
+251
+00:18:14,000 --> 00:18:16,000
+doesn't have any messages to read.
+
+252
+00:18:17,000 --> 00:18:21,000
+Let me open condition interface to explore its methods together with you.
+
+253
+00:18:22,000 --> 00:18:25,000
+The first method in this list here is a wait.
+
+254
+00:18:25,000 --> 00:18:29,000
+Basically, this is similar method to the weight from object class.
+
+255
+00:18:29,000 --> 00:18:34,000
+It just makes thread wait for notification in case of interruption.
+
+256
+00:18:34,000 --> 00:18:37,000
+Sirat will be interrupted and we will get interrupted.
+
+257
+00:18:37,000 --> 00:18:38,000
+Exception.
+
+258
+00:18:39,000 --> 00:18:42,000
+The next method is a weight uninterruptedly.
+
+259
+00:18:42,000 --> 00:18:44,000
+This method has self described me.
+
+260
+00:18:45,000 --> 00:18:51,000
+This is similar to a weight mass, but was only one difference in case thread would be interrupted during
+
+261
+00:18:51,000 --> 00:18:57,000
+the waiting thread would keep waiting until get notified without interruption and waiting on a smattered
+
+262
+00:18:57,000 --> 00:19:02,000
+waits until a threat would be is interrupted or notified or specified.
+
+263
+00:19:02,000 --> 00:19:04,000
+Waiting time elapses.
+
+264
+00:19:04,000 --> 00:19:07,000
+We have another variation of a wave method here.
+
+265
+00:19:07,000 --> 00:19:11,000
+You can specify waiting time in any time you wish.
+
+266
+00:19:11,000 --> 00:19:19,000
+I wait until takes date as an argument to track waiting time signal MassArt wakes up once read only.
+
+267
+00:19:20,000 --> 00:19:25,000
+This method is similar to notify method from object class and signal all mass.
+
+268
+00:19:25,000 --> 00:19:27,000
+It is similar to the notify all method.
+
+269
+00:19:28,000 --> 00:19:34,000
+Now when we know the interface and understood the theory, let's look at the code example I open.
+
+270
+00:19:34,000 --> 00:19:35,000
+Condition them a file.
+
+271
+00:19:36,000 --> 00:19:38,000
+In this file we have simple demo.
+
+272
+00:19:39,000 --> 00:19:43,000
+We can push messages to stack and read messages from the stack.
+
+273
+00:19:43,000 --> 00:19:46,000
+I have value for maximum stack capacity.
+
+274
+00:19:46,000 --> 00:19:50,000
+I have static variables that is initialized with length list object.
+
+275
+00:19:50,000 --> 00:19:52,000
+After that I declare lock felt.
+
+276
+00:19:53,000 --> 00:19:58,000
+Using this lock field, I create the conditions condition for the case.
+
+277
+00:19:58,000 --> 00:20:00,000
+One stack is empty and conditional for the case.
+
+278
+00:20:00,000 --> 00:20:01,000
+One stack is four.
+
+279
+00:20:01,000 --> 00:20:04,000
+And reached its maximum capacity.
+
+280
+00:20:04,000 --> 00:20:12,000
+Now let's review Tomas's pushed the stack and popped from stack and push the stack, acquire a log after
+
+281
+00:20:12,000 --> 00:20:17,000
+that and verify the condition in case Texas would reach a maximum of its capacity.
+
+282
+00:20:17,000 --> 00:20:24,000
+We would stay in the loop here waiting to be notified that state is changed and redirect messages from
+
+283
+00:20:24,000 --> 00:20:33,000
+Stack in case we still didn't reach maximum capacity then with just any message to a stack and we notify
+
+284
+00:20:33,000 --> 00:20:37,000
+all threats that were waiting for stack empty condition updates.
+
+285
+00:20:38,000 --> 00:20:46,000
+Now the stack is not empty and readers may read messages and finally block release the log the next
+
+286
+00:20:46,000 --> 00:20:48,000
+MassArt is pop from Stack.
+
+287
+00:20:48,000 --> 00:20:54,000
+I acquired the lock and key stack size is zero and there is nothing to read.
+
+288
+00:20:54,000 --> 00:21:01,000
+This thread is waiting to be notified and once read is notified we just return the message from the
+
+289
+00:21:01,000 --> 00:21:01,000
+stack.
+
+290
+00:21:02,000 --> 00:21:08,000
+And finally, Block will notify all threats who were waiting for Stack full condition after the semester
+
+291
+00:21:08,000 --> 00:21:10,000
+to execute it at least once.
+
+292
+00:21:10,000 --> 00:21:17,000
+Stack is not full for sure because we read one message from the stack and we need to notify threats
+
+293
+00:21:17,000 --> 00:21:23,000
+which want to put a new message in stack that this is possible to do now also and release the log and
+
+294
+00:21:23,000 --> 00:21:25,000
+finally block in the main mass.
+
+295
+00:21:25,000 --> 00:21:31,000
+At a great instance of this demo class, I create executive service and I submit two tasks.
+
+296
+00:21:32,000 --> 00:21:37,000
+No matter in what order I would submit these tasks, the result would be the same.
+
+297
+00:21:37,000 --> 00:21:41,000
+I submit the task that reads text from Stack first.
+
+298
+00:21:41,000 --> 00:21:44,000
+After that I submit tasks that push message to stack.
+
+299
+00:21:45,000 --> 00:21:52,000
+Let me run this program and in console you can see that message from Stack has been read in case reader
+
+300
+00:21:52,000 --> 00:21:54,000
+Thirsk started first.
+
+301
+00:21:54,000 --> 00:22:01,000
+It reached the point of condition check and was moved into Wetterstedt after writer task message to
+
+302
+00:22:01,000 --> 00:22:06,000
+a stack reader got notified and returns tranquilly.
+
+303
+00:22:06,000 --> 00:22:07,000
+That was read.
+
+304
+00:22:07,000 --> 00:22:08,000
+Is this clear?
+
+305
+00:22:09,000 --> 00:22:14,000
+Also, sometimes methods of entry look also might be helpful.
+
+306
+00:22:14,000 --> 00:22:19,000
+Personally, myself, don't use Ransome's log methods very often.
+
+307
+00:22:19,000 --> 00:22:25,000
+I still prefer to work on the log abstraction level, but I must inform you that they are also useful
+
+308
+00:22:25,000 --> 00:22:28,000
+methods that you may use to build your logic.
+
+309
+00:22:28,000 --> 00:22:36,000
+I open the source code of reinforcement law, get hold count returns a number of holes on this log by
+
+310
+00:22:36,000 --> 00:22:38,000
+the current threat or zero.
+
+311
+00:22:38,000 --> 00:22:44,000
+If this log is not held by the current threat is held by current threat returns.
+
+312
+00:22:44,000 --> 00:22:45,000
+True or false?
+
+313
+00:22:45,000 --> 00:22:52,000
+True is returned if current threat holds this log and false otherwise is locked, Masset returns.
+
+314
+00:22:52,000 --> 00:22:58,000
+True, if any threat holds this lock and force otherwise is fair method returns true.
+
+315
+00:22:58,000 --> 00:23:04,000
+If this lock has fairness set true Heskey threats returns true.
+
+316
+00:23:04,000 --> 00:23:11,000
+If there may be other threats waiting to acquirer's lock get kulaks, return the estimated number of
+
+317
+00:23:11,000 --> 00:23:13,000
+threats and waiting for this lock.
+
+318
+00:23:13,000 --> 00:23:20,000
+As a waiter, Samatha takes argument of condition type and returns as true in case any weight and threats
+
+319
+00:23:20,000 --> 00:23:23,000
+for this condition get weight.
+
+320
+00:23:23,000 --> 00:23:28,000
+Killens return the estimated number of waiting for the specific condition.
+
+321
+00:23:28,000 --> 00:23:32,000
+Now you know all the matters of race and class.
+
+322
+00:23:32,000 --> 00:23:34,000
+Sure, this will help you someday.
+
+323
+00:23:35,000 --> 00:23:36,000
+Great.
+
+324
+00:23:36,000 --> 00:23:38,000
+Let's continue now.
+
+325
+00:23:38,000 --> 00:23:39,000
+Let's read.
+
+326
+00:23:39,000 --> 00:23:39,000
+Write.
+
+327
+00:23:39,000 --> 00:23:45,000
+Look, there is a separate interface that declares to massas read, log and write, log.
+
+328
+00:23:45,000 --> 00:23:47,000
+These masses should return.
+
+329
+00:23:47,000 --> 00:23:52,000
+You object of log type one you should use read, write, log.
+
+330
+00:23:52,000 --> 00:23:59,000
+It is a good way to improve performance by separating logs for reason and the logs for writing rule.
+
+331
+00:23:59,000 --> 00:24:07,000
+Simple user, no write logs and nobody is writing to the containment or changing state of the object.
+
+332
+00:24:07,000 --> 00:24:13,000
+This means that there is no harm in all threads read in the state of the object.
+
+333
+00:24:13,000 --> 00:24:20,000
+Thus, reblock may be acquired by multiple threads simultaneously and in case somebody is reading,
+
+334
+00:24:20,000 --> 00:24:28,000
+it is not allowed to update state at this moment to avoid inconsistency when nobody's reading and we
+
+335
+00:24:28,000 --> 00:24:35,000
+are writing update in the state of the object we can't acquire reblock to, not with data that is going
+
+336
+00:24:35,000 --> 00:24:42,000
+to be updated in a few seconds and only once read can acquire, write, log simultaneously does it make
+
+337
+00:24:42,000 --> 00:24:42,000
+sense.
+
+338
+00:24:43,000 --> 00:24:50,000
+And performance is better because rats are not waiting for log in cases when there is no harm in concurrent
+
+339
+00:24:50,000 --> 00:24:50,000
+execution.
+
+340
+00:24:51,000 --> 00:24:51,000
+Understood.
+
+341
+00:24:52,000 --> 00:24:57,000
+The most popular implementation of Read Write Log is a recent read write log.
+
+342
+00:24:58,000 --> 00:25:01,000
+This class implements two masses from read write.
+
+343
+00:25:01,000 --> 00:25:08,000
+Interface and also this class has it's similar to reinterred lower class is a mass that we have used
+
+344
+00:25:09,000 --> 00:25:17,000
+like is for good Kranks get weight killings and others, but all masses are considering the fact that
+
+345
+00:25:17,000 --> 00:25:19,000
+they're working with two locks.
+
+346
+00:25:19,000 --> 00:25:22,000
+For example, get you Lancs.
+
+347
+00:25:22,000 --> 00:25:29,000
+MassArt estimates the total number of threats that the wait and talk while both looks read and write
+
+348
+00:25:29,000 --> 00:25:32,000
+Whitelock such mass as headwaiters.
+
+349
+00:25:32,000 --> 00:25:38,000
+That takes a specific condition as measured argument will be the same for specific condition of specific
+
+350
+00:25:38,000 --> 00:25:46,000
+lock read or write decides that there are methods to check state of read and write separately.
+
+351
+00:25:47,000 --> 00:25:50,000
+They are getting rid of count returns.
+
+352
+00:25:50,000 --> 00:25:54,000
+A number of looks held is right logged returns.
+
+353
+00:25:54,000 --> 00:26:02,000
+True, if any threat holds the right lock and force otherwise is right locked by current threat returns.
+
+354
+00:26:02,000 --> 00:26:10,000
+True, if the current threat holds the right lock and force otherwise get right hold count returns a
+
+355
+00:26:10,000 --> 00:26:16,000
+number of holes on the right lock by the current threat or zero is the right lock is not held by the
+
+356
+00:26:16,000 --> 00:26:17,000
+current threat.
+
+357
+00:26:18,000 --> 00:26:20,000
+Get rid hold count the same.
+
+358
+00:26:20,000 --> 00:26:28,000
+But for reblock Hesketh threats returns true if is a read or write lock has threats waiting to acquire
+
+359
+00:26:28,000 --> 00:26:29,000
+the lock.
+
+360
+00:26:29,000 --> 00:26:36,000
+Basically I believe that we performed a nice overview already and now it is time to look as a good example
+
+361
+00:26:36,000 --> 00:26:38,000
+of reinforcement read, write, lock usage.
+
+362
+00:26:39,000 --> 00:26:45,000
+In this example, we are going to implement basic operations with the hash map and we'll make it available
+
+363
+00:26:45,000 --> 00:26:51,000
+to use in current environment to keep performance of our interaction with the hash map.
+
+364
+00:26:51,000 --> 00:26:57,000
+On the top level, we are going to use reinforcement with right log to control access to critical sections
+
+365
+00:26:58,000 --> 00:27:02,000
+in the class and declare the field of hash map and read, write, log.
+
+366
+00:27:03,000 --> 00:27:09,000
+After that I use object of the entrance, read, write, log to keep the reference to the right and
+
+367
+00:27:09,000 --> 00:27:10,000
+read logs.
+
+368
+00:27:11,000 --> 00:27:17,000
+Basically inside the map you can use, read, write, log and get the reference to the read or write
+
+369
+00:27:17,000 --> 00:27:18,000
+log when needed.
+
+370
+00:27:18,000 --> 00:27:24,000
+But in this case, when I use, read and write logs multiple times, I would like to extract those as
+
+371
+00:27:24,000 --> 00:27:25,000
+separate variables.
+
+372
+00:27:26,000 --> 00:27:29,000
+I have to write methods that updates state of my hash map.
+
+373
+00:27:30,000 --> 00:27:37,000
+They are put and to remove and you can see the before actually update the state of the hash map I acquired.
+
+374
+00:27:37,000 --> 00:27:38,000
+Quite right log.
+
+375
+00:27:39,000 --> 00:27:45,000
+I'm doing the same thing when I add update or remove an entry in the map in all cases, acquire, write,
+
+376
+00:27:45,000 --> 00:27:48,000
+log and release it after operation is finished.
+
+377
+00:27:49,000 --> 00:27:56,000
+Also I have to write operations in this case get and contains key assets, considering the fact that
+
+378
+00:27:56,000 --> 00:27:59,000
+these methods don't change state of the map.
+
+379
+00:27:59,000 --> 00:28:06,000
+And also we need to be sure that when we read data from the map, no other threats updating the hash
+
+380
+00:28:06,000 --> 00:28:14,000
+map I acquired with before proceeding with operations and obviously I release log after operation is
+
+381
+00:28:14,000 --> 00:28:14,000
+finished.
+
+382
+00:28:15,000 --> 00:28:22,000
+In this case, I can secure all written operations to avoid any inconsistencies during the reading writing
+
+383
+00:28:22,000 --> 00:28:22,000
+operations.
+
+384
+00:28:23,000 --> 00:28:27,000
+Press a pause for a minute and look one more time at this example.
+
+385
+00:28:27,000 --> 00:28:34,000
+Make sure how to read and write looks are connected and try to understand one more time the logic.
+
+386
+00:28:34,000 --> 00:28:40,000
+Once you are sure that you don't have any questions regarding this example, we are going to press it.
+
+387
+00:28:40,000 --> 00:28:45,000
+And the last, but not least for today, is stamped law class.
+
+388
+00:28:45,000 --> 00:28:48,000
+It also supports both read and write locks.
+
+389
+00:28:49,000 --> 00:28:56,000
+It also has a feature for optimistic Lorcan for Reid operations log acquisition, Marcedes Return,
+
+390
+00:28:56,000 --> 00:29:04,000
+a stamp that is used in other methods, for example, to release a log or to check if the log is still
+
+391
+00:29:04,000 --> 00:29:04,000
+valid.
+
+392
+00:29:04,000 --> 00:29:08,000
+In all cases, Stamp has long time value.
+
+393
+00:29:08,000 --> 00:29:16,000
+The state of a stamped log consists of a version and the mode trend methods may return the special value
+
+394
+00:29:16,000 --> 00:29:23,000
+zero to represent failure to acquire access the three modes of stamp lock writing mode.
+
+395
+00:29:24,000 --> 00:29:31,000
+When you try to acquire and write log, it can be done using method write law, which exclusively acquires
+
+396
+00:29:31,000 --> 00:29:34,000
+the log book and if necessary, until available.
+
+397
+00:29:34,000 --> 00:29:42,000
+This method returns a stamp that can be used in method and walk right to release the log or in conversion
+
+398
+00:29:42,000 --> 00:29:43,000
+of the log.
+
+399
+00:29:43,000 --> 00:29:49,000
+In a minute, I will explain to you what conversion methods are and how we can apply conversions across
+
+400
+00:29:49,000 --> 00:29:50,000
+sweet modes.
+
+401
+00:29:51,000 --> 00:29:58,000
+Once the log is held in the right mode, no relatives may be obtained and optimistic rehabilitations
+
+402
+00:29:58,000 --> 00:29:59,000
+will fail.
+
+403
+00:30:00,000 --> 00:30:00,000
+Read in my.
+
+404
+00:30:01,000 --> 00:30:03,000
+When is tried to acquire a grid?
+
+405
+00:30:04,000 --> 00:30:11,000
+It can be done using the massive lock, which not exclusively acquires the lock locking as necessary
+
+406
+00:30:11,000 --> 00:30:18,000
+until available rechanneled a stamp that can be used to unlock a convert mode versions with a time limit
+
+407
+00:30:18,000 --> 00:30:25,000
+of try with lock and without a time limit are also provided optimistic reading.
+
+408
+00:30:25,000 --> 00:30:28,000
+This is new mode added in stamp lock.
+
+409
+00:30:28,000 --> 00:30:36,000
+This whole can move can be visualized as an advanced booking attempt for reblock which may or may not
+
+410
+00:30:36,000 --> 00:30:37,000
+be granted.
+
+411
+00:30:37,000 --> 00:30:38,000
+Method tracked.
+
+412
+00:30:38,000 --> 00:30:44,000
+Mr. Grid is used to read in optimistic mode this message tregenza stamp.
+
+413
+00:30:44,000 --> 00:30:51,000
+Only if the lock is not currently held in rightmost method to validate is used to validate.
+
+414
+00:30:51,000 --> 00:30:55,000
+If the weather threat optimistically are correct or not validate.
+
+415
+00:30:55,000 --> 00:30:56,000
+MassArt returns true.
+
+416
+00:30:56,000 --> 00:31:03,000
+If the lock has not been acquired in writing mode since appertaining and given stamp for cases where
+
+417
+00:31:03,000 --> 00:31:09,000
+the rate locks are needed for very short segments, optimistic Retallack acquisition can help improve
+
+418
+00:31:09,000 --> 00:31:10,000
+performance.
+
+419
+00:31:10,000 --> 00:31:18,000
+However, this has to be used with caution as the right threats can change the field's values and cause
+
+420
+00:31:18,000 --> 00:31:21,000
+logical issues in the code to be assured of threats.
+
+421
+00:31:21,000 --> 00:31:25,000
+Safe behavior, regardless, should be used stamped.
+
+422
+00:31:25,000 --> 00:31:32,000
+Lock Glass in Java also supports methods that conditionally provide conversions across the three months.
+
+423
+00:31:32,000 --> 00:31:36,000
+Yes, reconversion massas to convert to three possible modes.
+
+424
+00:31:36,000 --> 00:31:39,000
+Each conversion method takes long argument.
+
+425
+00:31:40,000 --> 00:31:42,000
+This is a stamp to identify as law.
+
+426
+00:31:43,000 --> 00:31:48,000
+For example, mascotry convert to write log the text stamp as an argument.
+
+427
+00:31:48,000 --> 00:31:55,000
+Attempts to upgrade and moad return a well-tried stamp if one of the next conditions is met.
+
+428
+00:31:55,000 --> 00:32:01,000
+Obviously that in case the lock is already in writing mode, it is instantly returned.
+
+429
+00:32:01,000 --> 00:32:08,000
+The second condition is the lock is in the original mode and there are no other readers or lock is an
+
+430
+00:32:08,000 --> 00:32:11,000
+optimistic mode and the right lock is immediately available.
+
+431
+00:32:12,000 --> 00:32:15,000
+In all other cases, zero is returned.
+
+432
+00:32:15,000 --> 00:32:19,000
+The next conversion method is to convert to reblock.
+
+433
+00:32:20,000 --> 00:32:25,000
+If the stamp represents a right log releases log and obtain a read look.
+
+434
+00:32:25,000 --> 00:32:29,000
+If the stamp represents a relook, then it is returned.
+
+435
+00:32:29,000 --> 00:32:36,000
+If the stamp is for an optimistic relock, then the read look is acquired and the stamp is returned.
+
+436
+00:32:36,000 --> 00:32:41,000
+This message returns zero in all other cases once the lock can't be acquired.
+
+437
+00:32:42,000 --> 00:32:45,000
+And the third method is to convert to optimistic read.
+
+438
+00:32:45,000 --> 00:32:52,000
+If the stamp represents holding the lock, then it is released and an observation stamp is returned.
+
+439
+00:32:53,000 --> 00:32:57,000
+If the stamp represents an optimistic read, then it is returned.
+
+440
+00:32:57,000 --> 00:33:02,000
+If it's validation is successful, this message returns zero in all other cases.
+
+441
+00:33:02,000 --> 00:33:08,000
+The important thing about stamp lock is that it is not read unlike reinforcement lock.
+
+442
+00:33:09,000 --> 00:33:16,000
+So critical sections are secure with stamped locks should not call other unknown methods that may try
+
+443
+00:33:16,000 --> 00:33:25,000
+to acquire locks, although you may pass a stamp to other methods that can use or converted in conclusion
+
+444
+00:33:25,000 --> 00:33:26,000
+about stamp locks.
+
+445
+00:33:26,000 --> 00:33:32,000
+I want to say that this is really a very powerful class that provides you with a lot of flexibility
+
+446
+00:33:32,000 --> 00:33:35,000
+to tune your current program execution when needed.
+
+447
+00:33:36,000 --> 00:33:42,000
+But also this flexibility comes with a lot of opportunities to shoot in your own lack in case you use
+
+448
+00:33:42,000 --> 00:33:43,000
+this tool incorrectly.
+
+449
+00:33:44,000 --> 00:33:49,000
+So in case you decide to use this class to win some milliseconds in the performance of your move, this
+
+450
+00:33:49,000 --> 00:33:56,000
+training program or the Safe Haven time, cinquera carefully about each line of code and how you acquire,
+
+451
+00:33:56,000 --> 00:33:59,000
+release and convert modes between each other.
+
+452
+00:34:00,000 --> 00:34:02,000
+Let's see, triggering lock API.
+
+453
+00:34:02,000 --> 00:34:08,000
+So if you would only think how much we learned about Lock API today, you would be amazed.
+
+454
+00:34:08,000 --> 00:34:12,000
+I believe today was very efficient lesson reviews multiple times.
+
+455
+00:34:12,000 --> 00:34:19,000
+If it is needed to understand more complex concepts because no information from this lesson, you would
+
+456
+00:34:19,000 --> 00:34:22,000
+be able to create concurrent applications like a.
+
+457
+00:34:23,000 --> 00:34:26,000
+Now let's recap what we have learned in this lesson.
+
+458
+00:34:26,000 --> 00:34:33,000
+In this lesson we have learned what is API now, you know, advantages of using log API over synchronize
+
+459
+00:34:33,000 --> 00:34:35,000
+blocks and synchronized methods.
+
+460
+00:34:35,000 --> 00:34:41,000
+Villains can create implementations of interface and read, write, log interface.
+
+461
+00:34:41,000 --> 00:34:48,000
+After this lesson, you can easily use interent, log and re-insurance read, write log classes also
+
+462
+00:34:48,000 --> 00:34:51,000
+explain you how to use for conditions.
+
+463
+00:34:51,000 --> 00:34:54,000
+And at the end of the lesson we have learned stamped log.
+
+464
+00:34:55,000 --> 00:34:56,000
+That's all for today.
+
+465
+00:34:57,000 --> 00:34:58,000
+Thanks a lot for your attention.
+
+466
+00:34:58,000 --> 00:35:00,000
+Have a great day and see you.
+
+467
+00:35:00,000 --> 00:35:01,000
+The next lesson.
+
diff --git a/27 - Multithreading/011 Source-code-of-all-Lock-API-examples.url b/27 - Multithreading/011 Source-code-of-all-Lock-API-examples.url
new file mode 100644
index 0000000000000000000000000000000000000000..ac052028a4a3fa3c3d71f26337b4eb3380318278
--- /dev/null
+++ b/27 - Multithreading/011 Source-code-of-all-Lock-API-examples.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/locks
\ No newline at end of file
diff --git a/27 - Multithreading/012 Synchronizers - CyclicBarrier, CountDownLatch, Semaphore, Exchanger & Phaser_en.srt b/27 - Multithreading/012 Synchronizers - CyclicBarrier, CountDownLatch, Semaphore, Exchanger & Phaser_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..22a4e005e7ff4e71344cb46f535bc9490502db25
--- /dev/null
+++ b/27 - Multithreading/012 Synchronizers - CyclicBarrier, CountDownLatch, Semaphore, Exchanger & Phaser_en.srt
@@ -0,0 +1,1624 @@
+1
+00:00:05,000 --> 00:00:10,000
+Hello, adjustments in this lesson, we're going to learn as the synchronization tools that will help
+
+2
+00:00:10,000 --> 00:00:16,000
+you to coordinate the execution of multiple threats, the group of such classes often called Synchronizer.
+
+3
+00:00:17,000 --> 00:00:22,000
+This doesn't mean that all of them are connected with one single interface and has the same methods.
+
+4
+00:00:22,000 --> 00:00:28,000
+But this means that this group of classes are intended to solve similar tasks in a different way and
+
+5
+00:00:28,000 --> 00:00:29,000
+with different features.
+
+6
+00:00:29,000 --> 00:00:32,000
+In this lesson, we're going to run five Synchronizer.
+
+7
+00:00:33,000 --> 00:00:34,000
+They are cyclic.
+
+8
+00:00:34,000 --> 00:00:43,000
+Barriere Countdown, large semaphore exchanger and Feyza also will focus on the differences between
+
+9
+00:00:43,000 --> 00:00:44,000
+these classes.
+
+10
+00:00:44,000 --> 00:00:50,000
+So if you have a set of threads that communicate with each other, we can simply reuse these classes
+
+11
+00:00:50,000 --> 00:00:56,000
+from JDK instead of trying to come up with a custom solution with a set of locks and condition objects
+
+12
+00:00:57,000 --> 00:00:58,000
+and the synchronous keyword.
+
+13
+00:00:59,000 --> 00:01:04,000
+Let's start our lesson and let's start our lesson today from Cyclic Barriere.
+
+14
+00:01:04,000 --> 00:01:10,000
+And as usual, let's understand first why we might want to use this class and what problem that is going
+
+15
+00:01:10,000 --> 00:01:15,000
+to help us to solve ensured this class implements Barriere Partan.
+
+16
+00:01:15,000 --> 00:01:18,000
+But this doesn't tell us a lot of things.
+
+17
+00:01:18,000 --> 00:01:26,000
+This person describes the case when any threat must stop and the one point barrier and can't proceed
+
+18
+00:01:26,000 --> 00:01:29,000
+until all other threats reach the same point.
+
+19
+00:01:29,000 --> 00:01:32,000
+And you can see nice visualization of this part on the slide.
+
+20
+00:01:33,000 --> 00:01:40,000
+All threats should reach one barrier and after this condition is met, we proceed our execution.
+
+21
+00:01:40,000 --> 00:01:47,000
+Let's look at the source code of cyclic barrier class and at code example I open source code of cyclic
+
+22
+00:01:47,000 --> 00:01:48,000
+Barriere class.
+
+23
+00:01:49,000 --> 00:01:55,000
+Let's look at the constructors we have to constructors declared in this class once, constructor within
+
+24
+00:01:55,000 --> 00:02:00,000
+parameter only and another one was in parameter plus runnable parameter.
+
+25
+00:02:01,000 --> 00:02:07,000
+So it looks like in all cases we need to parse the number of threats that should reach the barrier.
+
+26
+00:02:07,000 --> 00:02:13,000
+And in other constructor we might pass the same number plus random rules that would describe actions
+
+27
+00:02:13,000 --> 00:02:16,000
+that is needed to get done once the barrier is reached.
+
+28
+00:02:17,000 --> 00:02:23,000
+I believe you already understood that we will use this class when we need a fixed number of threats
+
+29
+00:02:23,000 --> 00:02:28,000
+that must wait for each other to reach a common point before continuing execution.
+
+30
+00:02:29,000 --> 00:02:31,000
+How we will notify that we reached the point.
+
+31
+00:02:32,000 --> 00:02:38,000
+Each threat should cause a way to Masset on the barrier instanced to signify reaching the common execution
+
+32
+00:02:38,000 --> 00:02:39,000
+point.
+
+33
+00:02:39,000 --> 00:02:46,000
+The threats that need to synchronize execution are also called parties and colon's a wait method is
+
+34
+00:02:46,000 --> 00:02:51,000
+how we can register that a certain threat has reached the barrier point.
+
+35
+00:02:51,000 --> 00:02:58,000
+So once the wait method is called the threat, Collinses method suspends execution until a specified
+
+36
+00:02:58,000 --> 00:03:01,000
+number of threats have called the same method on the barrier.
+
+37
+00:03:02,000 --> 00:03:07,000
+This situation, where the required number of threats have called a wait is called treatment.
+
+38
+00:03:07,000 --> 00:03:13,000
+Syberia, let's look at my code examples of them how to work with cyclic Barriere.
+
+39
+00:03:13,000 --> 00:03:17,000
+Let's consider that you need to find maximum value.
+
+40
+00:03:17,000 --> 00:03:20,000
+By the way, you are going to have the similar homburg.
+
+41
+00:03:20,000 --> 00:03:26,000
+I will not share with you here all of the solution, but in this lesson you will get significant hint
+
+42
+00:03:26,000 --> 00:03:28,000
+how to solve the home task.
+
+43
+00:03:28,000 --> 00:03:34,000
+The task will be about finding the maximum number in multidimensional array with multiple threats.
+
+44
+00:03:34,000 --> 00:03:37,000
+Each threat would find a maximum number in each row.
+
+45
+00:03:37,000 --> 00:03:42,000
+Even despite this example doesn't completely reproduce the similar scenario.
+
+46
+00:03:42,000 --> 00:03:44,000
+It is very close to the solution.
+
+47
+00:03:45,000 --> 00:03:50,000
+In this example, each threat would generate random numbers several times and would put it in the shared
+
+48
+00:03:50,000 --> 00:03:54,000
+list once all threats generated enough numbers.
+
+49
+00:03:54,000 --> 00:03:57,000
+We need to find the biggest one in the list.
+
+50
+00:03:57,000 --> 00:03:58,000
+Is that clear?
+
+51
+00:03:59,000 --> 00:04:05,000
+OK, let's come up with a solution and the at first and after that we will put this logic in code.
+
+52
+00:04:06,000 --> 00:04:10,000
+So we need cyclic variables, a specified number of threats.
+
+53
+00:04:10,000 --> 00:04:17,000
+Once each threat will generate all numbers we need to call a wait method on the barrier object to indicate
+
+54
+00:04:17,000 --> 00:04:20,000
+the threat has been reached the barrier.
+
+55
+00:04:20,000 --> 00:04:26,000
+And once all threats reach the barrier, we need to run a separate task that would find the biggest
+
+56
+00:04:26,000 --> 00:04:27,000
+number interlaced.
+
+57
+00:04:28,000 --> 00:04:28,000
+Does it make sense?
+
+58
+00:04:29,000 --> 00:04:34,000
+Let's review my implementation here and declare a few constants in this class.
+
+59
+00:04:35,000 --> 00:04:40,000
+The first constants to force the number of threats in my app that are going to be executed concurrently.
+
+60
+00:04:41,000 --> 00:04:47,000
+The next constant is an amount of numbers to be generated by each threat, and the third constant is
+
+61
+00:04:47,000 --> 00:04:48,000
+used to generate random number.
+
+62
+00:04:49,000 --> 00:04:53,000
+This is maximum amount of values that may be generated.
+
+63
+00:04:53,000 --> 00:04:57,000
+After that, I declare that I am going to have a cyclic barrier.
+
+64
+00:04:57,000 --> 00:04:59,000
+We will initialize it later with No.
+
+65
+00:04:59,000 --> 00:05:06,000
+Of threats and the callback function here where initialise have at least variable, this is containment,
+
+66
+00:05:06,000 --> 00:05:12,000
+where all threats will add generated numbers, considering the fact we have a threatening program here,
+
+67
+00:05:12,000 --> 00:05:17,000
+I initialize this list variable with the reference to the safe array list.
+
+68
+00:05:17,000 --> 00:05:20,000
+This is copy on write our list.
+
+69
+00:05:20,000 --> 00:05:23,000
+And also I have random variable here initialized.
+
+70
+00:05:24,000 --> 00:05:27,000
+I'm going to use a durance a generation of random numbers.
+
+71
+00:05:27,000 --> 00:05:29,000
+Let's investigate my main method.
+
+72
+00:05:29,000 --> 00:05:33,000
+Now I create an instance of this demo class.
+
+73
+00:05:33,000 --> 00:05:40,000
+I'm going to use this variable to invoke non static methods and to be able to create Masset references
+
+74
+00:05:40,000 --> 00:05:42,000
+to non static methods declared in this class.
+
+75
+00:05:43,000 --> 00:05:45,000
+After that, I initialize my berrier.
+
+76
+00:05:46,000 --> 00:05:51,000
+I put the number of threats that I expect would reach the barrier and they put the reference to the
+
+77
+00:05:51,000 --> 00:05:53,000
+masses that should be executed.
+
+78
+00:05:53,000 --> 00:05:55,000
+Once ostracods reaches a barrier.
+
+79
+00:05:55,000 --> 00:05:58,000
+It is called number generation callback.
+
+80
+00:05:58,000 --> 00:06:04,000
+In case you are not familiar with the method references and other functional style syntax in Java,
+
+81
+00:06:04,000 --> 00:06:10,000
+please refer to my functional programming course where I explain a lot of concepts about functional
+
+82
+00:06:10,000 --> 00:06:11,000
+programming style in Java.
+
+83
+00:06:12,000 --> 00:06:14,000
+Now let's look at this method.
+
+84
+00:06:15,000 --> 00:06:23,000
+I use benefits of Stream API to find max number among generated since I convert my stream into streams
+
+85
+00:06:23,000 --> 00:06:31,000
+that has Max Masset Max Massata a chance optional in and I extract from it and after that I print all
+
+86
+00:06:31,000 --> 00:06:38,000
+numbers that I have in my generated list and the biggest number and the main method I create executive
+
+87
+00:06:38,000 --> 00:06:38,000
+service.
+
+88
+00:06:39,000 --> 00:06:47,000
+This is fixed reticule for four threads in the next line, I submit for tasks that are going to be executed
+
+89
+00:06:47,000 --> 00:06:47,000
+concurrently.
+
+90
+00:06:48,000 --> 00:06:55,000
+Let's look at the mass that I use in MASSATA reference here generates numbers that should generate numbers
+
+91
+00:06:55,000 --> 00:07:02,000
+and put all of them into the shared container here, use objects of the random type and go next and
+
+92
+00:07:02,000 --> 00:07:05,000
+specified limit for the French to generate random value.
+
+93
+00:07:06,000 --> 00:07:13,000
+And after we finish the loop and generate a total numbers that generate, we're moving further one stretch,
+
+94
+00:07:13,000 --> 00:07:20,000
+which is where we need to go out with Masset to indicate that Serhat is arrived to the point and is
+
+95
+00:07:20,000 --> 00:07:21,000
+going to wait other other threats.
+
+96
+00:07:22,000 --> 00:07:25,000
+I print the return value by Outweight MassArt.
+
+97
+00:07:25,000 --> 00:07:27,000
+I wait message returns.
+
+98
+00:07:27,000 --> 00:07:31,000
+The arrival index of the current threat were index returned.
+
+99
+00:07:31,000 --> 00:07:38,000
+My expression get points minus one indicates the first to arrive and zero indicates the last to arrive.
+
+100
+00:07:39,000 --> 00:07:40,000
+For demo purposes.
+
+101
+00:07:40,000 --> 00:07:48,000
+I decided to print the result of get method after we submitted all tasks get parties which a number
+
+102
+00:07:48,000 --> 00:07:51,000
+of parties required to traipses barrier.
+
+103
+00:07:51,000 --> 00:07:56,000
+It looks like this a so-called let's run this program now and cancel output.
+
+104
+00:07:56,000 --> 00:07:59,000
+We can see the result of get past MASP.
+
+105
+00:07:59,000 --> 00:08:05,000
+So we have four here because we initialized our cyclic variables for and value.
+
+106
+00:08:06,000 --> 00:08:12,000
+After that I printed the list was generated numbers and the maximum value you can check.
+
+107
+00:08:12,000 --> 00:08:13,000
+Everything is correct here.
+
+108
+00:08:13,000 --> 00:08:16,000
+Also, you can see the result of her weight.
+
+109
+00:08:16,000 --> 00:08:18,000
+Masset printed by each thread.
+
+110
+00:08:18,000 --> 00:08:23,000
+You can see how the arrival index is different depending on Wenstrup arrived.
+
+111
+00:08:24,000 --> 00:08:28,000
+Press pause for a minute if it is needed to understand this example better.
+
+112
+00:08:28,000 --> 00:08:30,000
+In the case of any questions, let me know.
+
+113
+00:08:31,000 --> 00:08:31,000
+Those are swedo.
+
+114
+00:08:32,000 --> 00:08:34,000
+Let's proceed with the next example.
+
+115
+00:08:34,000 --> 00:08:38,000
+The next class that we are going to discuss is a countdown launch.
+
+116
+00:08:39,000 --> 00:08:45,000
+Countdown launch is used to make sure that the task waits for others before it starts.
+
+117
+00:08:46,000 --> 00:08:48,000
+We can simplify this even more.
+
+118
+00:08:48,000 --> 00:08:54,000
+A Countdown Large has a counter filled which you can decrement as we require.
+
+119
+00:08:54,000 --> 00:09:01,000
+In other words, this is a clause that allows one or more threats to wait until a set of operations
+
+120
+00:09:01,000 --> 00:09:04,000
+been performed in other threads completes.
+
+121
+00:09:05,000 --> 00:09:09,000
+But probably the main question here is how's the countdown?
+
+122
+00:09:09,000 --> 00:09:15,000
+Launch is different from cycling barriers that we have just learned we are going to answer this question
+
+123
+00:09:15,000 --> 00:09:15,000
+to.
+
+124
+00:09:16,000 --> 00:09:22,000
+But let's first have a demo of Countdown Large to understand what we are going to compare with cyclic
+
+125
+00:09:22,000 --> 00:09:23,000
+barrier.
+
+126
+00:09:23,000 --> 00:09:27,000
+OK, I open countdown launch demo file.
+
+127
+00:09:27,000 --> 00:09:30,000
+In this file, we're going to have a very simple example.
+
+128
+00:09:31,000 --> 00:09:38,000
+I have constant here that is equal to for this is the furthest we are going to use for a countdown in
+
+129
+00:09:38,000 --> 00:09:41,000
+the main, a accurate countdown launch.
+
+130
+00:09:41,000 --> 00:09:47,000
+This class has only one version of constructor and argument is a mandatory.
+
+131
+00:09:47,000 --> 00:09:51,000
+So we can't initialize Countdown Lache without count.
+
+132
+00:09:52,000 --> 00:09:54,000
+After that, a great executive service.
+
+133
+00:09:54,000 --> 00:09:55,000
+Pay attention.
+
+134
+00:09:55,000 --> 00:09:59,000
+I create fake sweat pull for two threads only not for.
+
+135
+00:10:00,000 --> 00:10:06,000
+In the next one, I'm going to submit four tasks that will be executed by two threats.
+
+136
+00:10:07,000 --> 00:10:10,000
+Let's look at the task that is going to be executed.
+
+137
+00:10:10,000 --> 00:10:16,000
+I create here instance of a worker type and person to construct as a reference to the countdown clock.
+
+138
+00:10:17,000 --> 00:10:22,000
+For the sake of the demo, I created the worker clause that relates to this example inside the same
+
+139
+00:10:22,000 --> 00:10:23,000
+file.
+
+140
+00:10:23,000 --> 00:10:24,000
+Let's look at it.
+
+141
+00:10:25,000 --> 00:10:32,000
+It implements Runnable interface with the help of constructor we initialize in a field in one method
+
+142
+00:10:32,000 --> 00:10:34,000
+we imitate that we are doing some work.
+
+143
+00:10:35,000 --> 00:10:41,000
+We also log's the moment before we call count down on my count down large object in the main mass that
+
+144
+00:10:41,000 --> 00:10:44,000
+we call a weight masset on the countdown.
+
+145
+00:10:44,000 --> 00:10:52,000
+Large object right after we have submitted for tasks and one task will be executed four times and we
+
+146
+00:10:52,000 --> 00:10:56,000
+will call Countdown four times until a counter will become zero.
+
+147
+00:10:56,000 --> 00:11:01,000
+Only after that we are good to proceed with program execution after a wait.
+
+148
+00:11:01,000 --> 00:11:07,000
+MassArt after that will print large is released and program will finish execution.
+
+149
+00:11:07,000 --> 00:11:09,000
+Let's run it now.
+
+150
+00:11:09,000 --> 00:11:15,000
+And Concilio, you can see that we called Countdown four times until we print lodge is released.
+
+151
+00:11:16,000 --> 00:11:18,000
+So this is how countdown count down lodge works.
+
+152
+00:11:19,000 --> 00:11:22,000
+And now when you know how come down Lache works.
+
+153
+00:11:22,000 --> 00:11:27,000
+Let's ask question what is the difference between this class and cyclic barrier?
+
+154
+00:11:28,000 --> 00:11:30,000
+Let me answer this question.
+
+155
+00:11:30,000 --> 00:11:34,000
+It also will help us to understand the countdown large better.
+
+156
+00:11:34,000 --> 00:11:41,000
+The first difference is that cyclic barrier works with sweat, but can down lodge works with tasks.
+
+157
+00:11:42,000 --> 00:11:48,000
+The remember that in the last example I put your extra attention on the fact that four tasks will be
+
+158
+00:11:48,000 --> 00:11:50,000
+executed by two threats.
+
+159
+00:11:51,000 --> 00:11:57,000
+You can find source code examples in attachments to this lesson and you can try to do the same trick
+
+160
+00:11:57,000 --> 00:11:58,000
+for cyclic.
+
+161
+00:11:58,000 --> 00:12:06,000
+I mean, having less than tasks, it would be hard to accomplish because in Sequeira you call a weight
+
+162
+00:12:06,000 --> 00:12:12,000
+loss that makes current threat waiting for other threats, not for other tasks.
+
+163
+00:12:12,000 --> 00:12:17,000
+Completion in Countdown Large calculate the number of countdown and location.
+
+164
+00:12:18,000 --> 00:12:24,000
+And in Sakakibara, we calculate the number of threats that called a weight masset on SABERA.
+
+165
+00:12:25,000 --> 00:12:26,000
+They understand the difference.
+
+166
+00:12:27,000 --> 00:12:31,000
+And now the thing is that cyclic barrier allows you to execute function.
+
+167
+00:12:31,000 --> 00:12:34,000
+Once also reached the same point.
+
+168
+00:12:35,000 --> 00:12:37,000
+You can't do the same thing in the countdown.
+
+169
+00:12:37,000 --> 00:12:38,000
+Watch.
+
+170
+00:12:39,000 --> 00:12:41,000
+The next thing is related to reusability.
+
+171
+00:12:42,000 --> 00:12:47,000
+You can reuse Sakakibara once barer is broken and all threats are released.
+
+172
+00:12:48,000 --> 00:12:54,000
+Once the barrier trips and security barrier, the count resets to its original value.
+
+173
+00:12:54,000 --> 00:12:59,000
+Basically, you can use it multiple times without any restriction countdown.
+
+174
+00:12:59,000 --> 00:13:01,000
+Lache can't be reduced.
+
+175
+00:13:01,000 --> 00:13:03,000
+One count arrives at zero.
+
+176
+00:13:03,000 --> 00:13:04,000
+It can't be reset.
+
+177
+00:13:05,000 --> 00:13:11,000
+And now the difference is that in the cyclic barrier, if one threat is interrupted by weight and then
+
+178
+00:13:11,000 --> 00:13:15,000
+all of the weight and stress will throw broken barrier exception.
+
+179
+00:13:16,000 --> 00:13:22,000
+Whereas in Countdown watch, if the current threat is interrupted, it will throw into the exception.
+
+180
+00:13:22,000 --> 00:13:24,000
+It will not impact Ancestress.
+
+181
+00:13:25,000 --> 00:13:28,000
+This is a difference between cyclic barer and countdown.
+
+182
+00:13:28,000 --> 00:13:31,000
+Large hope that it is clear now.
+
+183
+00:13:31,000 --> 00:13:33,000
+OK, this is clear.
+
+184
+00:13:33,000 --> 00:13:35,000
+Let's proceed with the next Synchronizer.
+
+185
+00:13:36,000 --> 00:13:43,000
+Let's learn how to work with a semaphore and what this SEMAFO term is not specific to adjudicate only
+
+186
+00:13:43,000 --> 00:13:46,000
+there's a common part in multiscreen programming.
+
+187
+00:13:46,000 --> 00:13:53,000
+Usually it is a variable or abstract data type used to control access to common resource by multiple
+
+188
+00:13:53,000 --> 00:13:59,000
+threats of execution and the word potential concurrency issues that may happen because of multiple threats
+
+189
+00:13:59,000 --> 00:14:02,000
+accessing the same piece of code simultaneously.
+
+190
+00:14:02,000 --> 00:14:06,000
+The simplest semaphore implementation is a plain variable that is changed.
+
+191
+00:14:07,000 --> 00:14:13,000
+For example, incremental commented on toggled dependent on programming defined conditions, and that
+
+192
+00:14:14,000 --> 00:14:20,000
+a way to imagine semaphore is to imagine a system that stores information about the number of threats
+
+193
+00:14:20,000 --> 00:14:26,000
+that got access to a particular resource to adjust this resource safely and track the number of threats
+
+194
+00:14:26,000 --> 00:14:28,000
+that released the resource.
+
+195
+00:14:28,000 --> 00:14:34,000
+And in case it is not allowed to grant access to the shared resource for more threats, then it is specified.
+
+196
+00:14:35,000 --> 00:14:39,000
+Threats should wait until simmer for would allow to enter critical section again.
+
+197
+00:14:40,000 --> 00:14:46,000
+Let's look at the source code of semaphore class and after that let's investigate the code exampled.
+
+198
+00:14:46,000 --> 00:14:50,000
+Together I open the source code of a similar class.
+
+199
+00:14:50,000 --> 00:14:52,000
+Let's look at constructors that we have.
+
+200
+00:14:53,000 --> 00:14:59,000
+We have two constructors available, one within parameter and another one within parameter.
+
+201
+00:14:59,000 --> 00:15:06,000
+Land value, so you have to parse the number of permits available Zipzer permits to enter the critical
+
+202
+00:15:06,000 --> 00:15:07,000
+section.
+
+203
+00:15:07,000 --> 00:15:14,000
+This value is theoretically even maybe negative in this case or Lasan must happen before any acquires
+
+204
+00:15:14,000 --> 00:15:15,000
+will be granted.
+
+205
+00:15:16,000 --> 00:15:20,000
+But practically most likely you would never pass negative value to the constructor.
+
+206
+00:15:21,000 --> 00:15:27,000
+And in the other version of constructor, you should possibly then that in case you pass through here.
+
+207
+00:15:27,000 --> 00:15:34,000
+That means you want to create a fair simmi for fair means that this semaphore will guarantee first in,
+
+208
+00:15:34,000 --> 00:15:36,000
+first out granting of permits.
+
+209
+00:15:36,000 --> 00:15:39,000
+And the contention false would mean the opposite.
+
+210
+00:15:39,000 --> 00:15:45,000
+Let me also show you a few the most important masses from this class track.
+
+211
+00:15:45,000 --> 00:15:46,000
+Why massive returns?
+
+212
+00:15:46,000 --> 00:15:54,000
+True, if a permit is available immediately and the quiet, as always, returns false in case permit
+
+213
+00:15:54,000 --> 00:15:59,000
+is not available instantly spread is blocked and waiting until the one will be available.
+
+214
+00:16:00,000 --> 00:16:07,000
+This method is overloaded and we have different versions of this massive try acquire with time out where
+
+215
+00:16:07,000 --> 00:16:14,000
+you can pass different time units values this massive return false in case waiting time elapsed and
+
+216
+00:16:14,000 --> 00:16:15,000
+permits wasn't acquired.
+
+217
+00:16:16,000 --> 00:16:19,000
+Also, there is a track and method within the parameter.
+
+218
+00:16:19,000 --> 00:16:24,000
+This method acquirer's is a given number of permits from this semaphore.
+
+219
+00:16:24,000 --> 00:16:30,000
+Only if all are available at the time of location and combination of the previous two.
+
+220
+00:16:30,000 --> 00:16:35,000
+You can pass the number of permits you want to acquire and timeout that you are happy to wait.
+
+221
+00:16:36,000 --> 00:16:40,000
+As you may also notice, acquire mass at Maestro interrupted exception.
+
+222
+00:16:41,000 --> 00:16:45,000
+Taking into account Serrat is in the weakened state, trying to acquire a permit.
+
+223
+00:16:45,000 --> 00:16:48,000
+It may be interrupted by another threat.
+
+224
+00:16:48,000 --> 00:16:54,000
+In case you want to make sure that threat won't be interrupted while waiting for a permit, you should
+
+225
+00:16:54,000 --> 00:16:57,000
+use Aguaje uninterruptedly MassArt.
+
+226
+00:16:57,000 --> 00:17:04,000
+The next message that I'd like you to know is one of these is this important message that we should
+
+227
+00:17:04,000 --> 00:17:09,000
+never forget to invoke when we want to release a permit and return it to a semaphore.
+
+228
+00:17:10,000 --> 00:17:16,000
+Also, this method is overloaded and we can release Masset within argument.
+
+229
+00:17:16,000 --> 00:17:21,000
+In this case, I may release more than one permit and return it to the semaphore.
+
+230
+00:17:22,000 --> 00:17:28,000
+Available Permits Method returns a number of programs that are available for acquisition at this moment
+
+231
+00:17:28,000 --> 00:17:29,000
+of time.
+
+232
+00:17:29,000 --> 00:17:30,000
+In the Semaphore.
+
+233
+00:17:31,000 --> 00:17:37,000
+I believe that you already understood that we can use semaphores to limit the number of concurrent threats.
+
+234
+00:17:37,000 --> 00:17:45,000
+Accessing a specific resource I open for demo class in this example will implement a simple login queue
+
+235
+00:17:45,000 --> 00:17:48,000
+to limit the number of users in our application.
+
+236
+00:17:48,000 --> 00:17:55,000
+We are going to use masses that we have just reviewed, track, wire release and available permits.
+
+237
+00:17:55,000 --> 00:18:00,000
+Let me run this program and I will walk you through the console output line by line.
+
+238
+00:18:00,000 --> 00:18:04,000
+I declare variables that will stores a number of available login permits.
+
+239
+00:18:05,000 --> 00:18:09,000
+So in this case, only ten people can be locked in simultaneously.
+
+240
+00:18:10,000 --> 00:18:16,000
+And all of the users who want to login should wait until one of the users who is already logged in would
+
+241
+00:18:16,000 --> 00:18:17,000
+call Logout MassArt.
+
+242
+00:18:18,000 --> 00:18:21,000
+I create executive service was for threats.
+
+243
+00:18:21,000 --> 00:18:28,000
+After that, I create an instance of this demo file and the the number of permits to construct the infrastructure.
+
+244
+00:18:28,000 --> 00:18:35,000
+You can see that we just initialize the semaphore property of our demo class with the number of permits
+
+245
+00:18:35,000 --> 00:18:40,000
+that we have passed to the constructor as humans, that we submit the same amount of tasks as we have
+
+246
+00:18:40,000 --> 00:18:43,000
+promised to access the to login.
+
+247
+00:18:43,000 --> 00:18:47,000
+We should run out of tasks after all of them are completed.
+
+248
+00:18:48,000 --> 00:18:54,000
+Try login Massoud, just acquire a permit from the semaphore and the case permit has been acquired.
+
+249
+00:18:55,000 --> 00:19:00,000
+I print text to consult about successful login in case permit has been acquired.
+
+250
+00:19:00,000 --> 00:19:03,000
+We recommend to try one more time later.
+
+251
+00:19:04,000 --> 00:19:06,000
+But this is just an example actually.
+
+252
+00:19:06,000 --> 00:19:13,000
+You can put any logic you need based on the status and if you manage to acquire a permit or not.
+
+253
+00:19:14,000 --> 00:19:19,000
+I wait two seconds only to let also as be completed as this is.
+
+254
+00:19:19,000 --> 00:19:20,000
+Again, for the sake of the demo.
+
+255
+00:19:21,000 --> 00:19:27,000
+In this case, when I would check amount of available permits to login, I would print zero to console.
+
+256
+00:19:27,000 --> 00:19:35,000
+By the way, this method just cause available permits method on my semaphore object and when I next
+
+257
+00:19:35,000 --> 00:19:42,000
+time try to login in Pernice already and then would enter as look in my trialogue enmasse.
+
+258
+00:19:42,000 --> 00:19:46,000
+But what would happen in case one of the users will log out.
+
+259
+00:19:47,000 --> 00:19:48,000
+I call logout Massud.
+
+260
+00:19:48,000 --> 00:19:52,000
+That simply releases a permit and returns back to Semaphore.
+
+261
+00:19:53,000 --> 00:19:58,000
+Now I can try to log in one more time and it is a success I.
+
+262
+00:19:59,000 --> 00:20:06,000
+To log in, so semaphore is like a counter that tracks how much prints are acquired, how many left
+
+263
+00:20:06,000 --> 00:20:11,000
+and how much again released, and you saw in the example how it works.
+
+264
+00:20:12,000 --> 00:20:14,000
+Now it is Stampfel exchanger.
+
+265
+00:20:15,000 --> 00:20:19,000
+Let's understand how exchange your class may be helpful.
+
+266
+00:20:19,000 --> 00:20:24,000
+Exchange helps us to exchange data between threats at some point.
+
+267
+00:20:24,000 --> 00:20:32,000
+Exchange is a generalized type so you can parameterize the instance of this type with the type of exchanging
+
+268
+00:20:32,000 --> 00:20:32,000
+data.
+
+269
+00:20:33,000 --> 00:20:40,000
+There is a synchronization point where my pair and swap elements actually there is not so many unique
+
+270
+00:20:40,000 --> 00:20:42,000
+behaviors in this stack.
+
+271
+00:20:43,000 --> 00:20:46,000
+Let's look at exchange your closed source code and good examples.
+
+272
+00:20:47,000 --> 00:20:49,000
+I open the exchange for class source code.
+
+273
+00:20:50,000 --> 00:20:53,000
+Basically, there's only one public Masset exchange.
+
+274
+00:20:53,000 --> 00:21:00,000
+It is Ovalau that you can call exchange Masset and parse the values that you want to send to another
+
+275
+00:21:00,000 --> 00:21:03,000
+threat and you receive another Willer in return.
+
+276
+00:21:03,000 --> 00:21:10,000
+This massive threat in waiting state because threat needs to wait until as a threat would arrive to
+
+277
+00:21:10,000 --> 00:21:14,000
+exchange point and a loaded version of the exchange.
+
+278
+00:21:14,000 --> 00:21:18,000
+Massive defines additional parameters long and time.
+
+279
+00:21:18,000 --> 00:21:24,000
+Yet we can define how long we allow one threat to wait for another before complete exchange.
+
+280
+00:21:24,000 --> 00:21:28,000
+And let's review the example I open exchanges.
+
+281
+00:21:28,000 --> 00:21:31,000
+Damul the first things that I do in mine, massive.
+
+282
+00:21:32,000 --> 00:21:35,000
+I create exchange object parametrized by string.
+
+283
+00:21:36,000 --> 00:21:39,000
+After that I declare two tasks in the task.
+
+284
+00:21:39,000 --> 00:21:45,000
+Number one, I call exchange Mastodon's Exchange object to get the message from as a threat and pass
+
+285
+00:21:45,000 --> 00:21:47,000
+the message to another threat.
+
+286
+00:21:47,000 --> 00:21:49,000
+After that I print message received.
+
+287
+00:21:50,000 --> 00:21:56,000
+Considering that exchange method moves our threatening to wait in state, we should handle potential
+
+288
+00:21:56,000 --> 00:21:57,000
+interrupted exception.
+
+289
+00:21:57,000 --> 00:22:00,000
+The second task is similar one.
+
+290
+00:22:00,000 --> 00:22:07,000
+The only difference is the text that I sent to another threat and a little bit different console output
+
+291
+00:22:07,000 --> 00:22:11,000
+here that indicates that this console output from another task.
+
+292
+00:22:11,000 --> 00:22:15,000
+After that, I create executor's service and submit my two tasks.
+
+293
+00:22:16,000 --> 00:22:23,000
+Then I shut down my executive service, let me run this program and in console output you can see how
+
+294
+00:22:23,000 --> 00:22:30,000
+messages from different tasks has been exchanged when each thread reached the exchange point.
+
+295
+00:22:30,000 --> 00:22:32,000
+Basically, that's it.
+
+296
+00:22:32,000 --> 00:22:34,000
+And this is how exchange works.
+
+297
+00:22:34,000 --> 00:22:35,000
+Let's continue.
+
+298
+00:22:36,000 --> 00:22:40,000
+And the last, but not least for today, is Fazer Closs.
+
+299
+00:22:40,000 --> 00:22:47,000
+Similar to second barrier Fazer implements very important, but provides us with more flexibility.
+
+300
+00:22:47,000 --> 00:22:52,000
+With this type, you can synchronize threads that represent separate phase.
+
+301
+00:22:52,000 --> 00:22:59,000
+Step of the whole execution goal of the common action is a number of threads that participate in this
+
+302
+00:22:59,000 --> 00:23:01,000
+process is not fixed.
+
+303
+00:23:01,000 --> 00:23:06,000
+It can be configured dynamically the same as cyclic barrier.
+
+304
+00:23:06,000 --> 00:23:12,000
+Fayza represents a synchronization point where multiple threads should meet each other.
+
+305
+00:23:12,000 --> 00:23:14,000
+One also has arrived.
+
+306
+00:23:14,000 --> 00:23:19,000
+Fazer goes to the next phase and waits also at the next point.
+
+307
+00:23:19,000 --> 00:23:26,000
+Important thing to mention here is that in most of the literature, often Fazer is compared with cyclic
+
+308
+00:23:26,000 --> 00:23:27,000
+barrier.
+
+309
+00:23:27,000 --> 00:23:28,000
+But why?
+
+310
+00:23:28,000 --> 00:23:30,000
+Why we don't compete with Countdown.
+
+311
+00:23:30,000 --> 00:23:38,000
+Large phase tracks threats but not actually tasks so recommended to call register Masset for the same
+
+312
+00:23:38,000 --> 00:23:43,000
+amount of stress that we'll call one of the mass that indicates arrival.
+
+313
+00:23:44,000 --> 00:23:49,000
+Let's compare Fazer with cyclic barria during the competition.
+
+314
+00:23:49,000 --> 00:23:55,000
+It is worth to mention next Sync's Let me flag the things that Fazer has and cyclic.
+
+315
+00:23:55,000 --> 00:23:58,000
+Berrier doesn't have support of multiple phases.
+
+316
+00:23:59,000 --> 00:24:05,000
+Each phase has no number of threats to participate and is not limited and is not fixed.
+
+317
+00:24:06,000 --> 00:24:10,000
+SVREP may take part and after that cancel on participation.
+
+318
+00:24:10,000 --> 00:24:13,000
+Threat shouldn't necessarily wait for other threats.
+
+319
+00:24:13,000 --> 00:24:17,000
+Reach the synchronization point to continue its work.
+
+320
+00:24:17,000 --> 00:24:22,000
+It is just enough to notify about arrival and proceed execution.
+
+321
+00:24:22,000 --> 00:24:26,000
+This is something what is available in Faisa but not available.
+
+322
+00:24:26,000 --> 00:24:29,000
+And second secondary in comparison to cyclic.
+
+323
+00:24:30,000 --> 00:24:34,000
+There is not action attached that potentially might be executed.
+
+324
+00:24:34,000 --> 00:24:37,000
+After all, threats reach specific point.
+
+325
+00:24:38,000 --> 00:24:44,000
+Definitely these are not all of the differences, but just a few main differences.
+
+326
+00:24:45,000 --> 00:24:51,000
+We're going to face a deeper in a few seconds and you would be able to find a lot of differences, too.
+
+327
+00:24:52,000 --> 00:24:53,000
+So let's have a demo.
+
+328
+00:24:53,000 --> 00:24:56,000
+I'm going to start from the source code of the Fazer class.
+
+329
+00:24:57,000 --> 00:24:58,000
+Let's review Main.
+
+330
+00:24:58,000 --> 00:25:06,000
+Instructors and methods to create further object, I recommend you to use one of the two possible constructors,
+
+331
+00:25:06,000 --> 00:25:10,000
+the default one without parameters and within the parameter.
+
+332
+00:25:10,000 --> 00:25:17,000
+If you create phaser with default constructor, Veria will be closed until all registered participants
+
+333
+00:25:17,000 --> 00:25:18,000
+would be Syberia.
+
+334
+00:25:18,000 --> 00:25:23,000
+In case a great Fazer was in argument, Barria will be open.
+
+335
+00:25:23,000 --> 00:25:26,000
+Once specified, number of threads would reach a barrier.
+
+336
+00:25:27,000 --> 00:25:31,000
+Also zero constructor was Faisa argument to pass the reference to the parent Feyza.
+
+337
+00:25:32,000 --> 00:25:36,000
+But we are not going to review it now because it is very rarely used.
+
+338
+00:25:37,000 --> 00:25:39,000
+Registered as it should be called.
+
+339
+00:25:39,000 --> 00:25:47,000
+When STREAT wants to participate in FAYZA is a massive ads and you are not party to the FAYZA now that
+
+340
+00:25:47,000 --> 00:25:54,000
+this only increases the number of registered parties and we can check whether the current threat is
+
+341
+00:25:54,000 --> 00:25:55,000
+registered or not.
+
+342
+00:25:56,000 --> 00:26:01,000
+Once the threat is arrived to Syberia, we should signal that it has arrived.
+
+343
+00:26:01,000 --> 00:26:05,000
+To do this, we need to call arrive and await Advance Masset.
+
+344
+00:26:06,000 --> 00:26:09,000
+This is a bloke in Massachusetts mussarat into waiting state.
+
+345
+00:26:09,000 --> 00:26:16,000
+When the number of arrived parties is equal to the number of registered parties, the execution of the
+
+346
+00:26:16,000 --> 00:26:21,000
+program will continue and the first number will increase in the case of threat.
+
+347
+00:26:21,000 --> 00:26:28,000
+Doesn't want to wait for other threats and just wants to continue with the next phase we need to invoke
+
+348
+00:26:28,000 --> 00:26:29,000
+arrive Masset.
+
+349
+00:26:30,000 --> 00:26:36,000
+This method signals that the threat reached is a barrier, usually different variations of methods that
+
+350
+00:26:36,000 --> 00:26:39,000
+indicate arrival return in value.
+
+351
+00:26:40,000 --> 00:26:42,000
+This is usually the number of the face.
+
+352
+00:26:43,000 --> 00:26:49,000
+If we know that our method will not participate in the next phase, we need to arrive.
+
+353
+00:26:49,000 --> 00:26:50,000
+And the register masset.
+
+354
+00:26:51,000 --> 00:26:56,000
+This method, the register threat from the Faisa was out of waiting Osas to arrive.
+
+355
+00:26:57,000 --> 00:27:04,000
+Current threat should no longer be accounted for in this particular phase and the following phases we
+
+356
+00:27:04,000 --> 00:27:08,000
+can get the current phase number by Colon's at Get Face MassArt.
+
+357
+00:27:09,000 --> 00:27:12,000
+Also, you can check the status of Faisa using Z methods.
+
+358
+00:27:13,000 --> 00:27:21,000
+Get registered parties will return the number of registered threats, get arrived parties which number
+
+359
+00:27:21,000 --> 00:27:24,000
+of arrived parties as a current face.
+
+360
+00:27:24,000 --> 00:27:28,000
+Let's now review code example and learn how to use this.
+
+361
+00:27:28,000 --> 00:27:30,000
+I open phase a demo class.
+
+362
+00:27:31,000 --> 00:27:36,000
+Let me run the program and I will walk you through the console output in the class.
+
+363
+00:27:36,000 --> 00:27:38,000
+I have one constant here.
+
+364
+00:27:38,000 --> 00:27:42,000
+This is just to be able to configure a number of threads quickly.
+
+365
+00:27:42,000 --> 00:27:49,000
+I create Faisa object that I'm going to use to synchronize the work of multiple threads in Maine.
+
+366
+00:27:49,000 --> 00:27:51,000
+Masset I create executive service.
+
+367
+00:27:51,000 --> 00:27:54,000
+I have fixed thread pool for demo purposes.
+
+368
+00:27:54,000 --> 00:27:58,000
+I print face no before we start the execution of tasks.
+
+369
+00:27:59,000 --> 00:28:04,000
+And when we have just created Faisa, the face number is equal to zero.
+
+370
+00:28:04,000 --> 00:28:08,000
+After that I submit the same number of tasks as total stress.
+
+371
+00:28:08,000 --> 00:28:14,000
+No, I have nested class task here that implements Runnable interface.
+
+372
+00:28:14,000 --> 00:28:19,000
+For the sake of the demo, I decided to keep all related examples inside the class.
+
+373
+00:28:20,000 --> 00:28:21,000
+Let's look at it.
+
+374
+00:28:21,000 --> 00:28:24,000
+We have Fayza property here that is initialized.
+
+375
+00:28:24,000 --> 00:28:30,000
+We are constructor also should have the reference to the same Faisa in order.
+
+376
+00:28:30,000 --> 00:28:32,000
+We could make synchronization of those threats.
+
+377
+00:28:32,000 --> 00:28:37,000
+Also in constructor I call, register and run Masset.
+
+378
+00:28:37,000 --> 00:28:39,000
+I have console output for demo purposes.
+
+379
+00:28:40,000 --> 00:28:46,000
+Once one method is started, you can execute any code you want that contains your business logic.
+
+380
+00:28:46,000 --> 00:28:53,000
+In our case I just print threatening and call arrived and the weight advanced method after that threat
+
+381
+00:28:53,000 --> 00:28:59,000
+sleeps for one hundred milliseconds to make sure that as a threat arrived to the same point.
+
+382
+00:29:00,000 --> 00:29:06,000
+This is for demo purposes only arrive and awaited once returns Richard's arrival face.
+
+383
+00:29:06,000 --> 00:29:08,000
+No, we are going to have one here.
+
+384
+00:29:09,000 --> 00:29:14,000
+After the sleep I will get face MassArt and I'm going to have the same No.
+
+385
+00:29:14,000 --> 00:29:22,000
+One here because we are in phase one already and phase was number zero is already the next thing I do
+
+386
+00:29:22,000 --> 00:29:22,000
+here.
+
+387
+00:29:23,000 --> 00:29:26,000
+I look again threatening and signal that threat is arrived.
+
+388
+00:29:27,000 --> 00:29:33,000
+Arrival first number would be to now and I the result of get the face masks one more time.
+
+389
+00:29:34,000 --> 00:29:36,000
+We are going to have to have two.
+
+390
+00:29:36,000 --> 00:29:44,000
+And once we are done with all steps and all phases, we can call arrive and the register method in my
+
+391
+00:29:44,000 --> 00:29:45,000
+masset.
+
+392
+00:29:45,000 --> 00:29:49,000
+I wait for one second to make sure that all threats are registered.
+
+393
+00:29:49,000 --> 00:29:56,000
+I call get registered parties Masset to make sure that no threats are registered in my favor anymore.
+
+394
+00:29:56,000 --> 00:29:57,000
+Is that clear?
+
+395
+00:29:58,000 --> 00:30:05,000
+Suppose for a minute and use this example also, as usual, you're going to have links to the old source
+
+396
+00:30:05,000 --> 00:30:12,000
+code examples, and I recommend you to run this example on your computer to understand better play with
+
+397
+00:30:12,000 --> 00:30:14,000
+different masses of Fazer object.
+
+398
+00:30:15,000 --> 00:30:18,000
+This should help you to understand this class better and any way.
+
+399
+00:30:18,000 --> 00:30:21,000
+In case you have any questions, please let me know.
+
+400
+00:30:22,000 --> 00:30:24,000
+You can leave your question below this here.
+
+401
+00:30:25,000 --> 00:30:28,000
+Now let's recap what we have learned in this lesson.
+
+402
+00:30:28,000 --> 00:30:33,000
+Now, you know what, Synchronizer, are we learned with your Santa Barbara countdown?
+
+403
+00:30:33,000 --> 00:30:36,000
+Large semaphore exchange and.
+
+404
+00:30:37,000 --> 00:30:41,000
+Now you know how these classes are different and how you can use them.
+
+405
+00:30:42,000 --> 00:30:43,000
+Thanks a lot for your attention.
+
+406
+00:30:44,000 --> 00:30:46,000
+Have a great day and see you as the next lesson.
+
diff --git a/27 - Multithreading/012 The-source-code-of-all-examples-from-the-lesson.url b/27 - Multithreading/012 The-source-code-of-all-examples-from-the-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..7f7b4dd47dd2418ef59eff0c7559974874cd6de6
--- /dev/null
+++ b/27 - Multithreading/012 The-source-code-of-all-examples-from-the-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/synchronizers
\ No newline at end of file
diff --git a/27 - Multithreading/013 Homework Multithreading_en.srt b/27 - Multithreading/013 Homework Multithreading_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..227ecd3023f11e033bb513227036bf97c28de071
--- /dev/null
+++ b/27 - Multithreading/013 Homework Multithreading_en.srt
@@ -0,0 +1,364 @@
+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.
+
diff --git a/27 - Multithreading/013 Homework-description.url b/27 - Multithreading/013 Homework-description.url
new file mode 100644
index 0000000000000000000000000000000000000000..f4aa0430de88ddbced30ef7c008a12a88c7faccf
--- /dev/null
+++ b/27 - Multithreading/013 Homework-description.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://docs.google.com/document/d/1iUGVwnOAitglW_MNpQSZjvZ2FyzE_T1m6k7q8eoBsug/edit?usp=sharing
\ No newline at end of file
diff --git a/27 - Multithreading/013 Homework-source-code-of-the-solution.url b/27 - Multithreading/013 Homework-source-code-of-the-solution.url
new file mode 100644
index 0000000000000000000000000000000000000000..4f6a5e20f72ee93f731b65e22b95019e49de2c1b
--- /dev/null
+++ b/27 - Multithreading/013 Homework-source-code-of-the-solution.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/hw
\ No newline at end of file
diff --git a/27 - Multithreading/014 Quiz Multithreading - Check yourself.html b/27 - Multithreading/014 Quiz Multithreading - Check yourself.html
new file mode 100644
index 0000000000000000000000000000000000000000..d475a46681a3bdc130f85570d9f20ba862ca91ba
--- /dev/null
+++ b/27 - Multithreading/014 Quiz Multithreading - Check yourself.html
@@ -0,0 +1,69 @@
+
+
+
+
+
+ Quiz Multithreading - Check yourself
+
+
+
+
+
+
+
Quiz Multithreading - Check yourself
+
Quiz Link: https://forms.gle/R17p8kRnfayKrCFSA
The quiz doesn’t require you to log in or submit any personal information. Your data privacy is my priority.
The Quiz covers content from the following lessons:
Introduction to Multithreading
First Multithreading Program: Thread & Runnable
Thread Scheduler, Race Condition, Daemon Threads & Thread Groups
Synchronization basics: Critical Areas, Monitor/Mutex, Synchronized
Memory Management in Multithreading Programs
Deadlock and Livelock
Executor Services, Callable & Future
Executor Service Implementations & ThreadFactory
Fork/Join Framework
CompletableFuture
Lock API - Lock, ReadWriteLock, ReentrantLock, ReentrantReadWriteLock, StampedLock
Synchronizers - CyclicBarrier, CountDownLatch, Semaphore, Exchanger & Phaser
Quiz Instructions:
This quiz is designed to help you check your understanding of the content from the previous lessons. All questions are based only on material covered in the lessons you've already watched, so there’s no need to worry about unfamiliar topics.
Each question has one correct answer. Select the best answer and click "Submit" when you're ready.
After submitting, you'll see your score. For each question, you earn 1 point.
Click "View Results" to see the explanations for each correct answer. Reviewing these explanations can help reinforce your understanding.
If you score below 70%, I recommend revisiting the previous lessons. However, if the explanations make sense and you’re confident in your understanding, feel free to move on.
If any explanations are unclear, please don’t hesitate to post questions in the Q&A section—I’m here to help!
+
+
+
+
diff --git a/27 - Multithreading/external-links.txt b/27 - Multithreading/external-links.txt
new file mode 100644
index 0000000000000000000000000000000000000000..4e869925d3802906ba16285d2f61b879893f07d9
--- /dev/null
+++ b/27 - Multithreading/external-links.txt
@@ -0,0 +1,66 @@
+
+002 Source-code-of-the-First-multithreading-program
+https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/FirstMultithreadingProgram.java
+
+002 Source-code-of-thread-interruption-demo
+https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/InterruptDemo.java
+
+003 Source-code-of-the-Priority-demo
+https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/PriorityDemo.java
+
+003 Source-code-of-the-yield-method-demo
+https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/YieldDemo.java
+
+003 Source-code-of-the-Thread-group
+https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/ThreadGroupDemo.java
+
+003 Source-code-of-the-daemon-threads
+https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/DaemonThreadDemo.java
+
+003 Source-code-of-throwing-exception-from-run-method-example
+https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/ThrowingExceptionFromRunnableDemo.java
+
+004 Source-code-of-all-examples-from-the-lesson
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/waitnotify
+
+005 AtomicInteger-demo-source-code
+https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/atomictypes/AtomicIntegerDemo.java
+
+005 ThreadLocal-demo-source-code
+https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/ThreadLocalDemo.java
+
+005 InheritablThreadLocal-demo-source-code
+https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/multithreading/InheritableThreadLocalDemo.java
+
+006 Deadlock-source-code-examples
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/deadlock
+
+006 Livelock-source-code-examples
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/livelock
+
+007 Executor-Services-source-code-of-demo
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/executors
+
+007 Callable-Future-source-code-of-demo
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/callable
+
+008 Executor-Service-Implementations-ThreadFactory-demo-source-code
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/executors
+
+009 Source-code-of-Fork-Join-examples
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/executors/forkjoin
+
+010 CompletableFuture-source-code-of-all-examples
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/completablefuture
+
+011 Source-code-of-all-Lock-API-examples
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/locks
+
+012 The-source-code-of-all-examples-from-the-lesson
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/synchronizers
+
+013 Homework-description
+https://docs.google.com/document/d/1iUGVwnOAitglW_MNpQSZjvZ2FyzE_T1m6k7q8eoBsug/edit?usp=sharing
+
+013 Homework-source-code-of-the-solution
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/multithreading/hw
diff --git a/28 - ===== Multithreading in Java Interview Preparation =====/001 Part 1 Java Multithreading Interview - Questions and Answers.html b/28 - ===== Multithreading in Java Interview Preparation =====/001 Part 1 Java Multithreading Interview - Questions and Answers.html
new file mode 100644
index 0000000000000000000000000000000000000000..011946f9400eaed0bec17b7750f9cd4fdda774ae
--- /dev/null
+++ b/28 - ===== Multithreading in Java Interview Preparation =====/001 Part 1 Java Multithreading Interview - Questions and Answers.html
@@ -0,0 +1,69 @@
+
+
+
+
+
+ Part 1 Java Multithreading Interview - Questions and Answers
+
+
+
+
+
+
+
Part 1 Java Multithreading Interview - Questions and Answers
+
A process is a unit of the operating system that is allocated memory and other resources. A thread is a unit of code execution. A thread has a stack - some of its memory for execution. The rest of a process's memory is shared by all of its threads. Threads run on processor cores.
In some OS, the difference between processes and threads is minimized.
There are several ways to create and run threads:
Don’t forget that Runnable and Callable are functional interfaces. That means that you can describe instance of this type with the help of lambda expression or method reference.
Access control to a resource object is provided by the concept of a monitor. An instance monitor can have only one owner. When attempting concurrent access to an object whose monitor has an owner, a thread wishing to lock the resource object must wait until that object's monitor is released before taking possession of it and beginning to use the resource object.
Following are some ways to synchronize in Java:
System synchronization using wait/notify. A thread that is waiting for any conditions to be met calls the wait method on this object, having previously captured its monitor. This stops his work. Another thread can call the notify method on the same object (again, having previously captured the object's monitor), as a result of which the thread waiting on the object "wakes up" and continues its execution.
System synchronization using join. The join method, called on an instance of the Thread class, allows the current thread to stop before the thread associated with this instance has finished running.
Using classes from the java.util.concurrent package, which provides a set of classes for organizing inter-thread communication. Examples of such classes are Lock, Semaphore, etc. The concept of this approach is to use atomic operations and variables.
Synchronization blocks and synchronized methods
These methods are designed for inter-thread synchronization, for the interaction of threads with each other.
How these methods work? First, they can only be called by the thread that has captured the monitor of the object for which these methods are called. That is, they are called inside the synchronized block and on the object whose monitor is captured by this synchronized keyword.
What does the wait() method do? The wait() method releases the object's monitor, so that other threads can now capture it (the monitor), that is, enter the synchronized block for this object. The wait() method then enters the wait state until another thread calls notify() or notifyAll() on the same object. After that, the thread in which wait() was called tries to capture the object's monitor again, and when the monitor becomes free, that is, when another thread releases it, it captures the monitor and continues execution from the next statement after wait(). Moreover, the thread that called wait() has no advantage over other threads waiting to capture the same monitor.
What do notify(), notifyAll() methods do? They "wake up" the thread waiting with the wait() method (if any) and put it into the state of waiting for the monitor to be released. The difference between notify() and notifyAll() is that notify() wakes up only one thread waiting with the wait() method, which one will be awakened cannot be determined, but notifyAll() - all such threads.
The difference between the methods is as follows:
final void wait() - the method is used in a multithreaded environment, can only be called by the thread that owns the synchronization object. In this case, the synchronization object is released, and the current thread goes into the mode of waiting for a signal of the release of the synchronization object by another thread by calling the notify() or notifyAll() method.
final void wait(long time) - similar to wait() , this method is used in a multithreaded environment, the current thread goes into the mode of waiting for a signal to release the synchronization object by another thread by calling the notify() or notifyAll() method. In case the wait occurs for the specified time, then execution continues unconditionally.
Main differences:
yield() method - attempts to tell the thread scheduler to execute another thread that is waiting in the execution queue. The method does not attempt to put the current thread into a blocking, sleeping, or waiting state. He just tries to transfer it from the "working" state to the "workable" state. However, executing a method may have no effect at all. Thread state remains RUNNABLE
sleep() method - suspends the thread for the specified time. state changes to TIMED_WAITING, after expiration - RUNNABLE
the wait() method - changes the state of the thread to WAITING and can only be called on the object that owns the lock, otherwise an IllegalMonitorStateException will be thrown. When the method fires, the lock is released, allowing other threads waiting to acquire the same lock to continue. in the case of wait(int) with an argument, the state will be TIMED_WAITING.
The join() method is called in order to attach the current thread to the end of the thread on which the method is called. That is, the second thread will be in blocking mode until the first thread is executed.
This is when one thread A received a lock on object A1, and thread B received a lock on object B1. While thread A tries to acquire a lock on object B1, and thread B on A1.
Imagine a situation that two threads simultaneously change the state of some object, this is unacceptable. To do this, you need to synchronize the threads. How to do it? The synchronized keyword allows you to do this by setting it in the method signature. Or, in the method, you can describe the synchronized block, only as a parameter you need to pass an object that will be blocked.
Imagine a situation where one thread is waiting for an object to be unlocked... what if there are several threads waiting for it? There is no guarantee that the object that has been waiting the most for the lock to be released will be executed first.
Static synchronized methods and non-static synchronized methods will not block each other, ever. Static methods are blocked on an instance of the class Class while non-static methods are blocked on the current instance (this). These actions do not interfere with each other.
wait() - releases the lock;
Brief description of the keywords:
volatile - indicates that the field is synchronized across multiple threads
synchronized - indicates that the method is synchronized, or the method can contain a synchronization block.
transient - indicates that the variable is not to be serialized
native - indicates that the implementation of the method is written on a different software platform
The thread priority is a number from 1 to 10, depending on which the thread scheduler chooses which thread to run. However, you cannot rely on priorities for predictable execution of a multithreaded program!
These are threads that run in the background and are not guaranteed to complete. That is, if all threads have completed, then the daemon thread simply terminates along with the application closing.
You can put a thread to sleep using the sleep(long ms) method.
ms - time in milliseconds.
When this method is called, the thread goes to sleep, after sleep, the thread goes to the thread pool and is in the "healthy" state, i.e. it is not guaranteed that after awakening it will be executed immediately. Also, a thread cannot put another thread to sleep, since the sleep method is a static method! You will simply put the current thread to sleep and nothing more! Also, the sleep() method can throw an InterruptedException() in case Thread will be interrupted while thread is in sleep state.
We have a current thread running the main method. This thread has its own stack, and this stack begins with a call to the main method.
Next, in the main method, we create a new thread, what happens? A new thread is created and its own stack is allocated for it with the original run () method.
When we start multiple threads, we cannot guarantee a certain order of their calls. Thread scheduling is handled by the JVM thread scheduler, choosing a thread from pools of threads. We can't even guarantee that if the first thread started running first, then it will finish running first, it may finish running last.
Another nuance is that a thread that has finished its execution cannot be restarted! It is in the "dead" state, and to start a new thread, the object must be in the "new" state.
Threads have the following states:
new (this is when an instance of the Thread class was just created)
alive or running (it enters this state after starting the start() method, but this does not mean that the thread is already running! Or it can enter this state from the running or blocked state)
running (this is when the run() method started executing)
waiting (waiting) / Blocked (blocked) / Sleeping (sleeping). These states characterize the thread as not ready for operation. I combined these states because they all have one thing in common - the thread is still alive (alive), but currently cannot be executed. In other words, the thread is no longer running, but it can return to a running state. The thread may be blocked, which means that it is waiting for the release of some resources. The thread can sleep if the sleep(long s) method is encountered, or it can wait if the wait() method is encountered, it will wait until the notify() or notifyall() method is called.
dead (the state when the run() method has completed its work)
+
+
+
+
diff --git a/28 - ===== Multithreading in Java Interview Preparation =====/002 Part 2 Java Multithreading Interview - Questions and Answers.html b/28 - ===== Multithreading in Java Interview Preparation =====/002 Part 2 Java Multithreading Interview - Questions and Answers.html
new file mode 100644
index 0000000000000000000000000000000000000000..90ad3050c2fff520d0c1a2bc7d31ac5ed3d48c0f
--- /dev/null
+++ b/28 - ===== Multithreading in Java Interview Preparation =====/002 Part 2 Java Multithreading Interview - Questions and Answers.html
@@ -0,0 +1,69 @@
+
+
+
+
+
+ Part 2 Java Multithreading Interview - Questions and Answers
+
+
+
+
+
+
+
Part 2 Java Multithreading Interview - Questions and Answers
+
Main differences:
The Runnable interface was introduced in Java 1.0, and the Callable interface was introduced in Java 5.0 as part of the java.util.concurrent library.
Classes that implement the Runnable interface must implement the run() method in order to execute a task. Classes that implement the Callable interface must implement the call() method to complete the task.
The Runnable.run() method does not return any value, its type is void, and the Callable.call() method can return a value of type T. The Callable interface is a parameterized Callable<T> and the type of value that will be returned in the call() method is given by this parameter T.
The run() method cannot throw a checked exception, while the call() method can throw a checked exception.
Although both of these synchronizers allow threads to wait for each other, the main difference between them is that you cannot reuse CountDownLatch after its count reaches zero, but you can use CyclicBarrier again even after the barrier is broken.
Race conditions are the cause of subtle bugs. As the name says, a race condition is caused by a race condition between multiple threads, if the thread that should run first loses the race and the second one runs, the behavior of the code changes, causing non-deterministic bugs. These are some of the hardest bugs to catch and reproduce, due to the erratic nature of races between threads. An example of a race condition is erratic execution.
Java provides rich APIs for everything, but, ironically, doesn't provide a convenient way to stop a thread. JDK 1.0 had several control methods like stop() , suspend() and resume() which were marked as deprecated in future releases due to potential deadlock threats, since then the Java API developers have made no attempt to introduce a persistent, thread -safe and elegant way to stop threads. Programmers mostly rely on the fact that a thread stops itself as soon as it finishes executing the run() or call() methods. To stop manually, programmers take advantage of the interrupt() method that switches the flag inside the thread and throws interrupted exception when the thread is in waiting state.
This is one of the good trick questions. In simple words, if an exception is not caught, the thread is dead, if a handler for uncaught exceptions is installed, it will receive a callback.
Thread.UncaughtExceptionHandler is an interface defined as a nested interface for handlers to be called when a thread suddenly stops due to an uncaught exception. When a thread is about to stop due to an uncaught exception, the JVM will check for an UncaughtExceptionHandler using Thread.getUncaughtExceptionHandler() and call the uncaughtException() method on the handler, passing the thread and the exception as arguments.
ThreadLocal variables are a special kind of variable available to the Java programmer.
This is a good way to achieve thread-safety for expensive-to-create objects, for example you can make SimpleDateFormat thread-safe using ThreadLocal. Because it is an expensive class, it is not desirable to use it in a local scope that requires separate instances per call. By giving each thread its own copy, you kill two birds with one stone. First, you reduce the number of expensive object instances by reusing a fixed number of instances, and second, you achieve thread-safety, no loss of synchronization, and no immutability. Another good example of a thread-local variable is the ThreadLocalRandom class, which reduces the number of instances of expensive-to-create Random objects in a multi-threaded environment.
FutureTask is a cancelable asynchronous computation in a parallel Java application. This class provides a basic implementation of Future, with methods for starting and stopping a calculation, methods for querying the state of a calculation, and retrieving results. The result can only be retrieved when the computation is complete, the getter will block if the computation has not yet completed. FutureTask objects can be used to wrap Callable and Runnable objects. Since FutureTask implements Runnable, it can be passed to an Executor for execution.
The main difference between interrupted() and isInterrupted() is that the first resets the interrupt status while the latter does not. The interrupt mechanism in Java is implemented using an internal flag known as interrupt status. Interrupting a thread by calling Thread.interrupt() sets this flag. When an interrupted thread checks the interrupt status by calling the static Thread.interrupted() method, the interrupt status is reset. The non-static isInterrupted() method, which is used by a thread to check the interrupt status of another thread, does not change the interrupt flag. By convention, any method that terminates by throwing an InterruptedException will reset the interrupt flag. However, there is always the possibility that the flag will immediately be set again if another thread calls interrupt().
The main reason for calling wait and notify from within a synchronized block or method is that the Java API absolutely requires it. If you call them from a non-synchronized block, your code will throw an IllegalMonitorStateException.
A more subtle reason is to avoid race conditions between wait and notify calls.
Creating a thread is expensive in terms of time and resources. If you create a thread while a request is being processed, it will slow down the response time, and the process can only create a limited number of threads. To avoid these problems, a pool of threads is created during application startup and the threads are reused to process requests. This pool of threads is called the "thread pool", and the threads in it are the worker thread. Starting with Java 1.5, the Java API provides an Executor framework that allows you to create different thread pools, such as a single thread pool that processes only one job per unit of time, a fixed thread pool, a pool with a fixed number of threads, and a cached thread pool, an expandable pool, suitable for applications with many short duration jobs. There are also other executor services are available.
Livelock is similar to deadlock, in the fact that the productivness of the program is zero. The difference is that in livelock the states of threads or involved processes constantly change depending on each other. Livelock is a special case of resource starvation. A real life example of a livelock is when two people meet in a narrow hallway and each, trying to be polite, steps aside, and so they move endlessly from side to side.
java.lang.Thread has a holdsLock() method that returns true if and only if the current thread is holding the monitor on a specific object.
The -Xss parameter is used to control the size of a thread's stack in Java.
There were times when the only way to achieve mutex was through the synchronized keyword, but it has several drawbacks, like you can't extend lock outside of a method or block of code, and so on. Java 5 solves this problem by providing finer control through the Lock interface. ReentrantLock is a common implementation of Lock that provides a Lock with the same basic behavior and semantics as an implicit monitor, achieved using synchronized methods, but with more features.
Semaphore is a new type of synchronizer. This is a semaphore with a counter. Conceptually, a semaphore manages a set of permissions. Each acquire() blocks, if necessary, before the permission is available, then acquires it. Each release() adds a permission, potentially releasing the blocking acquirer. However, this does not use the actual permission objects; The semaphore simply keeps the number available and acts accordingly. A semaphore is used to secure expensive resources that are scarcely available, such as a pooled database connection.
Both methods are ways of submitting a task to the thread pool, but there is a slight difference between them. Execute(Runnable command) is defined in the Executor interface and executes the given task in the future, but more importantly, returns nothing. On the other hand, submit() is an overloaded method, it can accept Runnable and Callable tasks, and can return a Future object that can be used to cancel execution and/or wait for the result of a calculation. This method is defined in the ExecutorService interface, which inherits from the Executor interface, and every thread pool class, such as ThreadPoolExecutor or ScheduledThreadPoolExecutor, inherits these methods.
A blocking method is a method that blocks until the task is completed, for example the accept() method on a ServerSocket blocks while waiting for a client to connect. Here, blocking means that control will not return to the calling method until the task is completed. On the other hand, there are asynchronous or non-blocking methods that complete before the task is completed.
In general, ReadWriteLock is the result of a lock parsing technique to improve the performance of parallel applications. This is an interface that was added in Java 5. It operates on a pair of related locks, one for reads and one for writes. A read lock can be held by multiple reading threads at the same time, as long as there are no write threads. The writing lock is exclusive. If you like, you can implement an interface with your ruleset, or you can use ReentrantReadWriteLock, which supports a maximum of 65535 recursive write locks and 65535 recursive read locks.
This is an old way of creating a thread-safe singleton that tries to optimize performance by only blocking when the singleton is first instantiated.
The Fork/Join framework, introduced in JDK 7, is a powerful utility that allows a developer to take advantage of multiple processors in modern servers. It is designed for work that can be recursively broken down into small particles. The goal is to use all available computing power to increase the performance of your application. One significant advantage of this framework is that it uses a work-stealing algorithm. Worker threads that have run out of jobs can "steal" jobs from other threads that are still busy.
+
+
+
+
diff --git a/29 - Date and Time in JDK/001 Source-code-of-example-from-the-lesson.url b/29 - Date and Time in JDK/001 Source-code-of-example-from-the-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..738799ffec9bdd0e14188d10639a8d50c54f6461
--- /dev/null
+++ b/29 - Date and Time in JDK/001 Source-code-of-example-from-the-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/date/Demo.java
\ No newline at end of file
diff --git a/29 - Date and Time in JDK/001 Time Standards (GMT, UTC), Date and Calendar from java.util_en.srt b/29 - Date and Time in JDK/001 Time Standards (GMT, UTC), Date and Calendar from java.util_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..f363f2861f83c55e2b82827bae3c5fa4f46ca66e
--- /dev/null
+++ b/29 - Date and Time in JDK/001 Time Standards (GMT, UTC), Date and Calendar from java.util_en.srt
@@ -0,0 +1,1204 @@
+1
+00:00:05,000 --> 00:00:06,000
+Hello, Jim.
+
+2
+00:00:06,000 --> 00:00:12,000
+In this lesson, we're going to start learning JDK API that will allow us to work with date and time
+
+3
+00:00:12,000 --> 00:00:13,000
+in our Java programs.
+
+4
+00:00:13,000 --> 00:00:19,000
+I can say already at the beginning of the lessons it's working with dates and times in Jaedicke is probably
+
+5
+00:00:19,000 --> 00:00:25,000
+the most chaotic topic because you can work with different classes from different packages that are
+
+6
+00:00:25,000 --> 00:00:29,000
+doing the same thing in a different way or slightly another thing.
+
+7
+00:00:30,000 --> 00:00:36,000
+But still, it's worse to know different classes that exist because different classes from JDK relies
+
+8
+00:00:36,000 --> 00:00:42,000
+on different abstractions and you need to use specific implementations that works best in conjunction
+
+9
+00:00:42,000 --> 00:00:44,000
+with other specific classes.
+
+10
+00:00:44,000 --> 00:00:47,000
+In this lesson, we are going to start from series in order.
+
+11
+00:00:47,000 --> 00:00:50,000
+You could understand what a time is.
+
+12
+00:00:50,000 --> 00:00:56,000
+I'm sure you know what a time is, but I would like to cover specifics of different times, standards
+
+13
+00:00:57,000 --> 00:00:59,000
+that are used across the world and in programming.
+
+14
+00:01:00,000 --> 00:01:06,000
+After Valencias, I will start explaining such basic classes from JDK as calendar and date.
+
+15
+00:01:07,000 --> 00:01:13,000
+Both of these classes are located in Geritol package, as this is important to understand, because
+
+16
+00:01:13,000 --> 00:01:17,000
+there's also another date class from Java Out package.
+
+17
+00:01:18,000 --> 00:01:22,000
+It is completely another class and used for other purposes.
+
+18
+00:01:22,000 --> 00:01:27,000
+We're going to learn that one one will see in this lesson.
+
+19
+00:01:27,000 --> 00:01:33,000
+You are going to understand what Unix epoch is, how to parse it from string and formatted according
+
+20
+00:01:33,000 --> 00:01:37,000
+to specific time zone and lots more in this lesson.
+
+21
+00:01:37,000 --> 00:01:39,000
+We're going to have a lot of examples.
+
+22
+00:01:39,000 --> 00:01:46,000
+And at the end of the lesson, I will explain drawbacks of calendar and date type and why there was
+
+23
+00:01:46,000 --> 00:01:47,000
+a need in relation.
+
+24
+00:01:47,000 --> 00:01:53,000
+Java Time package in Java eight, by the way, will also cover classes from Java Time package, but
+
+25
+00:01:53,000 --> 00:01:55,000
+not in this lesson in the next one.
+
+26
+00:01:56,000 --> 00:01:59,000
+Let's start with the first starting line JDK.
+
+27
+00:01:59,000 --> 00:02:05,000
+Let me share with you a small piece of theory about time that will help us to understand this topic
+
+28
+00:02:05,000 --> 00:02:05,000
+better.
+
+29
+00:02:06,000 --> 00:02:13,000
+The different I would call the time measurement standards since the world zero such terms as Greenwich
+
+30
+00:02:13,000 --> 00:02:17,000
+Time UTC Time your next time you t time.
+
+31
+00:02:17,000 --> 00:02:24,000
+You already know what a Unix time is, but let's now understand what the other terms mean.
+
+32
+00:02:24,000 --> 00:02:29,000
+Universal time is a time standard based on Earth's rotation.
+
+33
+00:02:30,000 --> 00:02:36,000
+There are several versions of universal time which differ by up to a few seconds.
+
+34
+00:02:36,000 --> 00:02:40,000
+The most commonly used occurred in that universal time.
+
+35
+00:02:41,000 --> 00:02:48,000
+UTC and you one also the different versions like T zero you to you two one.
+
+36
+00:02:48,000 --> 00:02:56,000
+Are all of these versions of you t except for UTC are based on Earth's rotation relative to distant
+
+37
+00:02:56,000 --> 00:02:59,000
+celestial objects, stars and quasars.
+
+38
+00:03:00,000 --> 00:03:07,000
+But with a scaling factor and other adjustments to make them closer to solid time for you to see is
+
+39
+00:03:07,000 --> 00:03:11,000
+based on International Atomic Time with leap seconds added.
+
+40
+00:03:12,000 --> 00:03:15,000
+GMT stands for Greenwich Mean Time.
+
+41
+00:03:15,000 --> 00:03:22,000
+It is a mean time and the Royal Observatory in Greenwich, London, counted from midnight at different
+
+42
+00:03:22,000 --> 00:03:23,000
+times.
+
+43
+00:03:23,000 --> 00:03:29,000
+In the past, it has been calculated in different ways, including being calculated from Moon.
+
+44
+00:03:29,000 --> 00:03:36,000
+As a consequence, it cannot be used to specify a particular time unless a context is given.
+
+45
+00:03:36,000 --> 00:03:43,000
+People usually use GMT as a synonym for coordinated, universal time UTC in modern usage.
+
+46
+00:03:43,000 --> 00:03:45,000
+This is incorrect.
+
+47
+00:03:45,000 --> 00:03:49,000
+GMT is now a time zone, not a time reference.
+
+48
+00:03:50,000 --> 00:03:55,000
+The term GMT should not just be used for purposes that require precision.
+
+49
+00:03:55,000 --> 00:04:00,000
+Also, the date glass is intended to reflect coordinated, universal time.
+
+50
+00:04:00,000 --> 00:04:06,000
+It may not do so exactly depending on the host environment of the Java virtual machine.
+
+51
+00:04:07,000 --> 00:04:13,000
+Nearly all modern operating systems assumes that one day is equal to twenty four hours times.
+
+52
+00:04:13,000 --> 00:04:15,000
+Sixty minutes in our time.
+
+53
+00:04:15,000 --> 00:04:17,000
+Sixty seconds in a minute.
+
+54
+00:04:17,000 --> 00:04:23,000
+That is equal to eighty six thousand four hundred seconds in the ATC.
+
+55
+00:04:23,000 --> 00:04:31,000
+However, about once every year or two there is an extra second called and the second the leap second
+
+56
+00:04:31,000 --> 00:04:37,000
+is always added as the last second of the day and always on December thirty first June surges.
+
+57
+00:04:38,000 --> 00:04:45,000
+For example, the last minute of the year, nineteen ninety five was six to one seconds long, thanks
+
+58
+00:04:45,000 --> 00:04:46,000
+to an added leap.
+
+59
+00:04:46,000 --> 00:04:52,000
+Second, most computer clocks are not accurate enough to be able to reflect the leap.
+
+60
+00:04:52,000 --> 00:04:53,000
+Second distinction.
+
+61
+00:04:53,000 --> 00:04:57,000
+What do you need to know is that the Earth's rotation is not uniform.
+
+62
+00:04:58,000 --> 00:05:01,000
+It slows down and speeds up in complicated ways.
+
+63
+00:05:02,000 --> 00:05:03,000
+It does not always.
+
+64
+00:05:03,000 --> 00:05:11,000
+Low, uniformally, leap seconds are introduced as needed in the U.S. so as to keep UTC within zero
+
+65
+00:05:11,000 --> 00:05:18,000
+point nine seconds of each one, which is a version of it, was a certain corrections apply there all
+
+66
+00:05:18,000 --> 00:05:21,000
+the time and the systems as well.
+
+67
+00:05:21,000 --> 00:05:29,000
+For example, the time scale used by satellite based Global Positioning System GPS is synchronized to
+
+68
+00:05:29,000 --> 00:05:32,000
+UTC but is not adjusted for leap seconds.
+
+69
+00:05:32,000 --> 00:05:36,000
+And now when you know all this, we are good to proceed with.
+
+70
+00:05:36,000 --> 00:05:42,000
+Learning time and date in Java today mostly will be learning APIs of different classes.
+
+71
+00:05:43,000 --> 00:05:50,000
+So I'm setting screens right away in order to review with your source code of classes and examples the
+
+72
+00:05:50,000 --> 00:05:57,000
+main classes that we are going to focus our attention on our calendar and they definitely will discuss
+
+73
+00:05:57,000 --> 00:05:59,000
+other classes do as we go.
+
+74
+00:05:59,000 --> 00:06:04,000
+But these two I mean, for today's lesson, let's start from Calanda.
+
+75
+00:06:05,000 --> 00:06:10,000
+I open them a file that is located in the aid package in our training project.
+
+76
+00:06:11,000 --> 00:06:15,000
+Feel free to find the reference to all them examples in the attachments to this lesson.
+
+77
+00:06:16,000 --> 00:06:22,000
+In this demo file, I'm going to have separate masses that Will Damos is a separate piece of functionality
+
+78
+00:06:22,000 --> 00:06:23,000
+or separate class.
+
+79
+00:06:24,000 --> 00:06:29,000
+I'm going to run this program and walk you through the console output as we go.
+
+80
+00:06:29,000 --> 00:06:32,000
+The first example is related to the class.
+
+81
+00:06:33,000 --> 00:06:34,000
+Let's open the class.
+
+82
+00:06:35,000 --> 00:06:39,000
+The first thing that is worth to mention here is that Canada is an abstract class.
+
+83
+00:06:40,000 --> 00:06:44,000
+This means that you need to choose which implementation you would like to use.
+
+84
+00:06:44,000 --> 00:06:49,000
+That's open type Iraqi and see what implementations do have here.
+
+85
+00:06:49,000 --> 00:06:57,000
+To be honest, Gregorian calendar, probably the most popular one, but also we have here Japanese Imperial
+
+86
+00:06:57,000 --> 00:07:00,000
+Calendar and Buddhist calendar.
+
+87
+00:07:01,000 --> 00:07:04,000
+Let's talk a little bit more about Canada as a time.
+
+88
+00:07:04,000 --> 00:07:10,000
+This time provides methods for converting between a specific instant in time and the set of calendar
+
+89
+00:07:10,000 --> 00:07:15,000
+fields such as year, month, day of the month, hour and so on.
+
+90
+00:07:16,000 --> 00:07:21,000
+And for manipulating the calendar fields, such as getting the date of the next week, for example,
+
+91
+00:07:22,000 --> 00:07:26,000
+and instant in time can be represented by milliseconds value.
+
+92
+00:07:26,000 --> 00:07:33,000
+That is an offset from the January 1st nineteen seventies midnight GMT.
+
+93
+00:07:33,000 --> 00:07:36,000
+This is called Unix Epoch Time.
+
+94
+00:07:37,000 --> 00:07:41,000
+Unix time is a system for describing a point in time.
+
+95
+00:07:41,000 --> 00:07:48,000
+It is a number of seconds that have elapsed since the Unix epoch minus leap seconds.
+
+96
+00:07:49,000 --> 00:07:56,000
+Zink's epoch is midnight UTC on January 1st, nineteen seventies and arbitrary date.
+
+97
+00:07:57,000 --> 00:08:02,000
+A lot of classis users this date as a zero point to calculate time in milliseconds.
+
+98
+00:08:02,000 --> 00:08:09,000
+Every positive number represents the time after January the 1st of seventies and negative value represents
+
+99
+00:08:09,000 --> 00:08:11,000
+all times before this date.
+
+100
+00:08:12,000 --> 00:08:19,000
+The class also provides additional fields and methods for implementing a complete calendar system outside
+
+101
+00:08:19,000 --> 00:08:19,000
+the package.
+
+102
+00:08:20,000 --> 00:08:25,000
+Let's now get back to the demo file in order you could see how to work with this type.
+
+103
+00:08:25,000 --> 00:08:29,000
+I believe this will help you to understand this type faster.
+
+104
+00:08:30,000 --> 00:08:36,000
+I declare a variable of calendar type and assign the object of Gregorian calendar.
+
+105
+00:08:36,000 --> 00:08:39,000
+This class has a lot of different constructors.
+
+106
+00:08:39,000 --> 00:08:44,000
+Let me open the source code of Gregorian calendar and investigate this with you.
+
+107
+00:08:45,000 --> 00:08:51,000
+The constructor, without any parameters creates as an object using current time in default time zone.
+
+108
+00:08:52,000 --> 00:08:56,000
+Or you can create calendar object for current time but in different time zone.
+
+109
+00:08:57,000 --> 00:09:02,000
+In this lesson I will also show you how to work with time zones and use them.
+
+110
+00:09:02,000 --> 00:09:05,000
+We can create calendar in different locale.
+
+111
+00:09:06,000 --> 00:09:10,000
+We are going to have separate lesson about localization and internationalization.
+
+112
+00:09:10,000 --> 00:09:13,000
+I will come a local topic in that lesson.
+
+113
+00:09:14,000 --> 00:09:16,000
+Just for the sake of this lesson.
+
+114
+00:09:16,000 --> 00:09:24,000
+You can imagine Glauco as an object that stores configuration and information about specific data formats,
+
+115
+00:09:24,000 --> 00:09:30,000
+representation for a particular region and operations that requires a local to perform.
+
+116
+00:09:30,000 --> 00:09:37,000
+Its task is called local sensitive and uses a local to tailor information for the user.
+
+117
+00:09:37,000 --> 00:09:43,000
+Also, we have constructors that allows us to instantiate Calanda object with different time units.
+
+118
+00:09:44,000 --> 00:09:49,000
+Yemens, the hour of the minutes, seconds, milliseconds.
+
+119
+00:09:50,000 --> 00:09:51,000
+Let me go back to them.
+
+120
+00:09:51,000 --> 00:09:56,000
+A file after I created can the object for the specified date.
+
+121
+00:09:56,000 --> 00:09:57,000
+I can work with it.
+
+122
+00:09:58,000 --> 00:10:03,000
+I use get that takes into argument instead of pure into.
+
+123
+00:10:04,000 --> 00:10:11,000
+I passed Constancia describe specific on the field, here is how I can extract the value of each field
+
+124
+00:10:12,000 --> 00:10:13,000
+for the sake of the Dharma.
+
+125
+00:10:13,000 --> 00:10:15,000
+I bring these values to console.
+
+126
+00:10:16,000 --> 00:10:24,000
+Let's move on now and want to review with the source code of another massive, simple date, for example,
+
+127
+00:10:24,000 --> 00:10:30,000
+another interesting class that is used together with Commander Endurance Data for Martin.
+
+128
+00:10:30,000 --> 00:10:33,000
+Simple data format from Java text package.
+
+129
+00:10:34,000 --> 00:10:36,000
+The idea is simple.
+
+130
+00:10:36,000 --> 00:10:43,000
+We can create an object of this type and pass the part that would describe how I want to form a date.
+
+131
+00:10:43,000 --> 00:10:46,000
+And each time it has its own placeholder.
+
+132
+00:10:47,000 --> 00:10:56,000
+For example, use Y for yes, use capital Tripoli and for months pay attention as the number of placeholders
+
+133
+00:10:56,000 --> 00:10:58,000
+also will impact the final formatting.
+
+134
+00:10:59,000 --> 00:11:06,000
+For example, in case you puts me in a row, this means that you want to print the name of the months,
+
+135
+00:11:07,000 --> 00:11:08,000
+but not months.
+
+136
+00:11:08,000 --> 00:11:16,000
+No, if I would have to m here, that would mean I want to bring sequential month's number was headings
+
+137
+00:11:16,000 --> 00:11:18,000
+zero in case I have months.
+
+138
+00:11:19,000 --> 00:11:20,000
+That is less than 10.
+
+139
+00:11:21,000 --> 00:11:22,000
+Does it make sense.
+
+140
+00:11:23,000 --> 00:11:29,000
+They is small the hours a capital H and after that we have minutes and seconds.
+
+141
+00:11:30,000 --> 00:11:37,000
+The whole list of placeholders and formatting rules you can find in official documentation of simple
+
+142
+00:11:37,000 --> 00:11:43,000
+date form of the class, probably the most popular placeholders and the rules we have just discussed.
+
+143
+00:11:43,000 --> 00:11:51,000
+But just in case you want a more open documentation for the class is a javadoc or just search and you
+
+144
+00:11:51,000 --> 00:11:54,000
+will find all the details in the source code.
+
+145
+00:11:54,000 --> 00:12:01,000
+Probably it will be hard for you to read this documentation because it uses a Chamoun markup.
+
+146
+00:12:01,000 --> 00:12:08,000
+But still, it is possible to understand after accurate and simple data format object, I want to print
+
+147
+00:12:08,000 --> 00:12:15,000
+to cancel the string that will be returned after invocation of format MASSELL form of mass uptakes date
+
+148
+00:12:15,000 --> 00:12:16,000
+object.
+
+149
+00:12:16,000 --> 00:12:17,000
+As a method argument.
+
+150
+00:12:17,000 --> 00:12:23,000
+You can easily convert calendar to date object by calling time as it is.
+
+151
+00:12:23,000 --> 00:12:24,000
+It returns date object.
+
+152
+00:12:25,000 --> 00:12:32,000
+And considering that I have Russian default lukow on my computer set now I see a shortened version of
+
+153
+00:12:32,000 --> 00:12:40,000
+my name in Russian, but a simple date format also has different constructors and one of the constructors
+
+154
+00:12:40,000 --> 00:12:42,000
+takes a call as its argument.
+
+155
+00:12:42,000 --> 00:12:47,000
+Now I can pass the United States the call and form on the same date.
+
+156
+00:12:47,000 --> 00:12:48,000
+With this formatter object.
+
+157
+00:12:49,000 --> 00:12:56,000
+I form a date with the help of this form data and let's look and cancel what we have now.
+
+158
+00:12:56,000 --> 00:12:58,000
+I February printed in English.
+
+159
+00:12:58,000 --> 00:13:05,000
+This is because of the call and let me create one more simple date format object and print the result
+
+160
+00:13:05,000 --> 00:13:06,000
+of formatting tokens.
+
+161
+00:13:06,000 --> 00:13:13,000
+So I created a new object of simple data format with slightly different button protections that we have
+
+162
+00:13:13,000 --> 00:13:16,000
+the same letters but different number of them.
+
+163
+00:13:16,000 --> 00:13:19,000
+For example, I have two Ys and one am.
+
+164
+00:13:20,000 --> 00:13:25,000
+Besides that I Parslow call and what we have and console in this case.
+
+165
+00:13:25,000 --> 00:13:28,000
+You can see that in console after formatting.
+
+166
+00:13:28,000 --> 00:13:33,000
+I see only to last the ages of here on a one digit represents the month.
+
+167
+00:13:34,000 --> 00:13:36,000
+February is the second month.
+
+168
+00:13:36,000 --> 00:13:37,000
+So everything is correct here.
+
+169
+00:13:38,000 --> 00:13:40,000
+That's how that format and works.
+
+170
+00:13:40,000 --> 00:13:43,000
+Press a pause for a minute to think about this example.
+
+171
+00:13:44,000 --> 00:13:48,000
+In case you have any questions, do not hesitate to write them below this video.
+
+172
+00:13:49,000 --> 00:13:50,000
+Let's review date example.
+
+173
+00:13:50,000 --> 00:13:58,000
+Now, similarly, I have separate masses, the second date example that contains all related lines of
+
+174
+00:13:58,000 --> 00:13:59,000
+code.
+
+175
+00:13:59,000 --> 00:14:07,000
+So let's review this massive date class represents a specific instant in time with millisecond precision
+
+176
+00:14:07,000 --> 00:14:15,000
+that has also different constructors, including constructors that allow us to set year, month, day
+
+177
+00:14:15,000 --> 00:14:16,000
+and other time units.
+
+178
+00:14:16,000 --> 00:14:20,000
+But this constructor is considered to be a deprecated Gnjidic.
+
+179
+00:14:20,000 --> 00:14:26,000
+In favor of the class are only two constructors that are not deprecated.
+
+180
+00:14:27,000 --> 00:14:29,000
+They are constructor without arguments.
+
+181
+00:14:29,000 --> 00:14:35,000
+That represents a time when it was created and constructor that takes milliseconds argument.
+
+182
+00:14:35,000 --> 00:14:40,000
+You already know what the Unix time is and what this milliseconds mean.
+
+183
+00:14:40,000 --> 00:14:42,000
+So here's an example.
+
+184
+00:14:42,000 --> 00:14:48,000
+For the sake of the demo, I create three objects of date time and you can see that Eclipse tells us
+
+185
+00:14:48,000 --> 00:14:50,000
+that constructor was specific.
+
+186
+00:14:50,000 --> 00:14:53,000
+Date is deprecated in the search constructor.
+
+187
+00:14:53,000 --> 00:14:57,000
+I pass actually random long veli and printed this data.
+
+188
+00:14:57,000 --> 00:15:00,000
+And so just look at the year.
+
+189
+00:15:00,000 --> 00:15:03,000
+I don't know what a solar system and.
+
+190
+00:15:03,000 --> 00:15:10,000
+You will exist by that time, but you can be sure that long time has enough in the seconds to cover
+
+191
+00:15:10,000 --> 00:15:14,000
+even this day, what are the ways to get that object?
+
+192
+00:15:15,000 --> 00:15:18,000
+We can pass that object from the street.
+
+193
+00:15:18,000 --> 00:15:24,000
+Imagine that you is a person somewhere page or you get the string as request argument.
+
+194
+00:15:25,000 --> 00:15:31,000
+Anyway, that might be different cases when you receive a date, a string, and you need to convert
+
+195
+00:15:31,000 --> 00:15:37,000
+it into date object in order to proceed working with this data to do this.
+
+196
+00:15:37,000 --> 00:15:41,000
+We again need help of simple date for math class.
+
+197
+00:15:41,000 --> 00:15:46,000
+I create object and describe the date patterns that I want to pass.
+
+198
+00:15:47,000 --> 00:15:50,000
+Then I call past my set of simple date format object.
+
+199
+00:15:51,000 --> 00:15:54,000
+This method returns the object of type date.
+
+200
+00:15:55,000 --> 00:16:00,000
+Also pay attention to the fact that this massive Maseru pass exception.
+
+201
+00:16:01,000 --> 00:16:05,000
+This may happen in case point was specified in simple date format.
+
+202
+00:16:05,000 --> 00:16:11,000
+Object can be applied to the string so that we have passed into the past.
+
+203
+00:16:11,000 --> 00:16:19,000
+Massell, in our specific case, format of date means our partner and we successfully get date objects.
+
+204
+00:16:20,000 --> 00:16:22,000
+I predict the console here.
+
+205
+00:16:23,000 --> 00:16:27,000
+I can convert date object back the string without any problems.
+
+206
+00:16:27,000 --> 00:16:30,000
+We already have our simple date form.
+
+207
+00:16:31,000 --> 00:16:39,000
+I just call MassArt format and POS date object and as a result I have the string that is formatted according
+
+208
+00:16:39,000 --> 00:16:39,000
+to the pattern.
+
+209
+00:16:40,000 --> 00:16:42,000
+Now let's look how to work.
+
+210
+00:16:42,000 --> 00:16:48,000
+Was a two time zone object in the separate matter time zone example.
+
+211
+00:16:48,000 --> 00:16:52,000
+I have a few lines of code that demonstrates how to work with time zone.
+
+212
+00:16:52,000 --> 00:17:00,000
+I create simple date, format, object, specify bottom and with a special set, a method I can set
+
+213
+00:17:00,000 --> 00:17:02,000
+time zone for this object.
+
+214
+00:17:02,000 --> 00:17:09,000
+This time zone will adjust the specified date according to the specific time zone I call Get Time Zone
+
+215
+00:17:09,000 --> 00:17:12,000
+Method and pass time zone Edesia.
+
+216
+00:17:13,000 --> 00:17:22,000
+This can be as an abbreviation such as S.T., a full name such as America Slash Los Angeles or custom
+
+217
+00:17:22,000 --> 00:17:25,000
+ID such as Jean T minus eight.
+
+218
+00:17:26,000 --> 00:17:34,000
+Working with thumb is always hard and also it is always hard to consider all possible time zones and
+
+219
+00:17:34,000 --> 00:17:35,000
+work with them properly.
+
+220
+00:17:36,000 --> 00:17:43,000
+But personally, myself, faced multiple times with business requirement to consider local time of the
+
+221
+00:17:43,000 --> 00:17:47,000
+user and a specific moment of time of program execution.
+
+222
+00:17:47,000 --> 00:17:55,000
+And the formatting we have just learned may help us later in this course will also other classes from
+
+223
+00:17:55,000 --> 00:17:58,000
+Java Time package that will do the same work.
+
+224
+00:17:59,000 --> 00:18:01,000
+I create object and formatted.
+
+225
+00:18:02,000 --> 00:18:09,000
+Time zone itself also has a lot of different methods, you can get specific offset or you can observe
+
+226
+00:18:09,000 --> 00:18:17,000
+Daylight Time Masset to check if some time zone is currently in daylight saving time as a part of your
+
+227
+00:18:17,000 --> 00:18:20,000
+homework looks through the source code of this class.
+
+228
+00:18:20,000 --> 00:18:26,000
+In my opinion, the most popular usage of this class is invocation of time zone massive.
+
+229
+00:18:27,000 --> 00:18:35,000
+Also after release and Java Time package, existing classes were updated with API that allows to convert
+
+230
+00:18:35,000 --> 00:18:39,000
+time between each other and work with different types.
+
+231
+00:18:40,000 --> 00:18:46,000
+For example, we can easily convert timezone into zone idea objects from Java Time package.
+
+232
+00:18:46,000 --> 00:18:54,000
+Later in this course, we'll also learn some IDE type and details you can call to Zone ID to convert
+
+233
+00:18:54,000 --> 00:18:55,000
+times on object.
+
+234
+00:18:56,000 --> 00:19:01,000
+Also, we can use this on I.D. to get Time Zone in the mind demo file.
+
+235
+00:19:01,000 --> 00:19:08,000
+I have another example I call overloaded version of Get Time Zone Masset that might take some ideas.
+
+236
+00:19:08,000 --> 00:19:17,000
+Musset argument static method of from zone and class maryjane zone i d by stream kinda or by offset
+
+237
+00:19:18,000 --> 00:19:21,000
+in case is started from plus or minus.
+
+238
+00:19:21,000 --> 00:19:24,000
+The string is taken as offset.
+
+239
+00:19:24,000 --> 00:19:32,000
+If the zone idea consists of a single letter, the zone idea is invalid and date time exception isro
+
+240
+00:19:32,000 --> 00:19:39,000
+I bring to this to console and you can see that actually the same day nunzia format and considering
+
+241
+00:19:39,000 --> 00:19:42,000
+different time zones shows different values.
+
+242
+00:19:43,000 --> 00:19:46,000
+Time zone objects also used in calendar time.
+
+243
+00:19:47,000 --> 00:19:54,000
+For example, there is a static method that is called get instance to instantiate Calanda object based
+
+244
+00:19:54,000 --> 00:19:55,000
+on your default or call.
+
+245
+00:19:55,000 --> 00:19:58,000
+The method takes time zone as a method argument.
+
+246
+00:19:59,000 --> 00:20:02,000
+You can also set time zone with a set a method.
+
+247
+00:20:03,000 --> 00:20:07,000
+Let's review another class now as it is called Zone ID.
+
+248
+00:20:08,000 --> 00:20:15,000
+As you saw, we already used it, but primarily this type is used in other classes from Java Time package.
+
+249
+00:20:16,000 --> 00:20:22,000
+But I believe it is verstraete of youth now because we can use it to create time zone object.
+
+250
+00:20:22,000 --> 00:20:25,000
+I have another method zone idea example.
+
+251
+00:20:26,000 --> 00:20:33,000
+In this simple example, I decided to go get available zones and print all of them to console and know
+
+252
+00:20:33,000 --> 00:20:40,000
+that you could investigate all the variety of time zone ideas that you can use during the instantiation
+
+253
+00:20:40,000 --> 00:20:41,000
+of time zone objects.
+
+254
+00:20:42,000 --> 00:20:47,000
+Get a variable time zones MARSAT return the set of strings with time zone I.D..
+
+255
+00:20:48,000 --> 00:20:54,000
+If you're interested how to work with streams and MassArt references, you can check my Java collections
+
+256
+00:20:54,000 --> 00:20:58,000
+framework and functional programming in Java courses.
+
+257
+00:20:58,000 --> 00:21:06,000
+I review such topics in details and here, for example, that shows how to convert date and calendar
+
+258
+00:21:06,000 --> 00:21:12,000
+between each other to convert date the calendar, just create an instance of a calendar and call set
+
+259
+00:21:12,000 --> 00:21:15,000
+time MassArt and pass date object as a method argument.
+
+260
+00:21:16,000 --> 00:21:19,000
+And if you want to convert calendar to date, just call.
+
+261
+00:21:19,000 --> 00:21:20,000
+Get time Masset.
+
+262
+00:21:20,000 --> 00:21:22,000
+It returns date object.
+
+263
+00:21:23,000 --> 00:21:31,000
+Is it now when you know calendar and date classes, let's try to understand why there was a need in
+
+264
+00:21:31,000 --> 00:21:37,000
+releasing new tools to work with Time in Java Time package on the Internet.
+
+265
+00:21:37,000 --> 00:21:45,000
+You can find different criticism against these classes, but in my opinion, none of comments is critical
+
+266
+00:21:45,000 --> 00:21:48,000
+enough to declare these classes as deprecated and dedicate.
+
+267
+00:21:48,000 --> 00:21:51,000
+I'm talking about the calendar and date.
+
+268
+00:21:51,000 --> 00:21:59,000
+That's why you may use these types whenever it is needed and they are still actively used by other classes
+
+269
+00:21:59,000 --> 00:21:59,000
+in JDK.
+
+270
+00:22:00,000 --> 00:22:06,000
+But still, I would like to draw your attention to some points, at least to make you aware of threat
+
+271
+00:22:06,000 --> 00:22:07,000
+safety.
+
+272
+00:22:07,000 --> 00:22:14,000
+The date and calendar classes are not safe, leaving developers to deal with potential multiscreen issues
+
+273
+00:22:15,000 --> 00:22:17,000
+and to write additional code to handle threat safety.
+
+274
+00:22:18,000 --> 00:22:26,000
+On the contrary, the new Date and Time API is introduced in Java eight, immutable and safe, thus
+
+275
+00:22:26,000 --> 00:22:33,000
+taking the concurrency headache away from developers API design and ease of understanding.
+
+276
+00:22:34,000 --> 00:22:40,000
+This drawback is also mentioned in the Internet by other engineers from Java Community.
+
+277
+00:22:40,000 --> 00:22:44,000
+I am not completely agree with it, but it contains seat of truth.
+
+278
+00:22:45,000 --> 00:22:51,000
+The date and the API are designed with an adequate mascot's to perform day to day operations.
+
+279
+00:22:51,000 --> 00:22:58,000
+I would say that it depends what the depravations to perform, but definitely the new daytime API is
+
+280
+00:22:58,000 --> 00:23:01,000
+ISO centric and follows consistent domain.
+
+281
+00:23:02,000 --> 00:23:09,000
+For the time, duration and periods, there are a wide variety of utility masses that support the most
+
+282
+00:23:09,000 --> 00:23:16,000
+common operations zone, date and time, developers had to write additional logic to handle time zone
+
+283
+00:23:16,000 --> 00:23:24,000
+logic with the old APIs and you research examples and what it took us to form a date according to the
+
+284
+00:23:24,000 --> 00:23:33,000
+time zone we are interested in, the things are different in our time package with the new API handling
+
+285
+00:23:33,000 --> 00:23:41,000
+of time zone can be done with local data and zoned the time API easier and more natural and object oriented
+
+286
+00:23:41,000 --> 00:23:42,000
+way.
+
+287
+00:23:42,000 --> 00:23:49,000
+These are a few of the main items that naturally let Oracle the release of the Java Time package.
+
+288
+00:23:49,000 --> 00:23:54,000
+But this is actually all what I wanted to share with you in this lesson.
+
+289
+00:23:54,000 --> 00:23:56,000
+Let's review what we have learned in this lesson.
+
+290
+00:23:57,000 --> 00:24:00,000
+In this lesson, we have learned a lot of interesting things.
+
+291
+00:24:01,000 --> 00:24:09,000
+Now you know what GMT and the ATC is and what is the difference between the standards, media and calendar
+
+292
+00:24:09,000 --> 00:24:10,000
+and Dave classes?
+
+293
+00:24:10,000 --> 00:24:16,000
+In the lesson we reviewed how to pass the string and format it back to strength.
+
+294
+00:24:16,000 --> 00:24:25,000
+We hold overview of the two time zone class and your code examples with it and examples of lessons learned,
+
+295
+00:24:25,000 --> 00:24:28,000
+drawbacks of calendar and date classes.
+
+296
+00:24:28,000 --> 00:24:30,000
+I'm sure you enjoyed the lesson.
+
+297
+00:24:31,000 --> 00:24:36,000
+After this lesson, we are ready to learn more about work with date and time and communicate in the
+
+298
+00:24:36,000 --> 00:24:37,000
+next lesson.
+
+299
+00:24:37,000 --> 00:24:42,000
+We are going to run classes from Java Time package and that's it for this lesson.
+
+300
+00:24:43,000 --> 00:24:45,000
+Thanks a lot for your attention team.
+
+301
+00:24:45,000 --> 00:24:48,000
+Have a great day and see you in the next lesson.
+
diff --git a/29 - Date and Time in JDK/002 Source-code-of-examples-from-the-lesson.url b/29 - Date and Time in JDK/002 Source-code-of-examples-from-the-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..7fe51f890d386ed6b82c22e2fa30140c860f067a
--- /dev/null
+++ b/29 - Date and Time in JDK/002 Source-code-of-examples-from-the-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/date
\ No newline at end of file
diff --git a/29 - Date and Time in JDK/002 java.time package (Instant, LocalDateTime, ZonedDateTime, OffsetDateTime etc)_en.srt b/29 - Date and Time in JDK/002 java.time package (Instant, LocalDateTime, ZonedDateTime, OffsetDateTime etc)_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..fb2d5bc6934cb58a1f69903c04a52aa863310741
--- /dev/null
+++ b/29 - Date and Time in JDK/002 java.time package (Instant, LocalDateTime, ZonedDateTime, OffsetDateTime etc)_en.srt
@@ -0,0 +1,1548 @@
+1
+00:00:05,000 --> 00:00:11,000
+How about him in this lesson, we're learning how to work with date and time, and you don't really
+
+2
+00:00:11,000 --> 00:00:17,000
+know the basics of working with time in Java and learning to different time standards and key terms.
+
+3
+00:00:17,000 --> 00:00:22,000
+If you didn't what the previous lesson about Time list did not skip it.
+
+4
+00:00:22,000 --> 00:00:26,000
+Make sure you watch the previous lesson before you get to this one.
+
+5
+00:00:27,000 --> 00:00:32,000
+In this lesson, we're going to run classes from Java Time package and how to work with that.
+
+6
+00:00:32,000 --> 00:00:36,000
+We are going to start from general overview of Java Time package.
+
+7
+00:00:36,000 --> 00:00:40,000
+I am going to explain you more about structure of this package.
+
+8
+00:00:40,000 --> 00:00:46,000
+And I will share with you my classification of all classes inside this package in order you can remember
+
+9
+00:00:46,000 --> 00:00:47,000
+them easier.
+
+10
+00:00:47,000 --> 00:00:53,000
+After that, we are going to spend a significant amount of time during the lesson to review the source
+
+11
+00:00:53,000 --> 00:01:00,000
+code of classes and code examples will review in detail such important classes as instant local date
+
+12
+00:01:00,000 --> 00:01:01,000
+time zones.
+
+13
+00:01:01,000 --> 00:01:09,000
+The time offset the time clock period, duration and many others in this class.
+
+14
+00:01:09,000 --> 00:01:12,000
+And I will show you how to work with these classes.
+
+15
+00:01:12,000 --> 00:01:14,000
+I prepared a lot of examples.
+
+16
+00:01:14,000 --> 00:01:18,000
+As usual, you can find source code with examples in attachments to the lesson.
+
+17
+00:01:19,000 --> 00:01:19,000
+Let's stop.
+
+18
+00:01:20,000 --> 00:01:24,000
+And before we get the code examples, let's learn a little bit of Siiri.
+
+19
+00:01:24,000 --> 00:01:30,000
+Let's quickly perform an overview of this package before we get closer to the concrete classes and source
+
+20
+00:01:30,000 --> 00:01:31,000
+code.
+
+21
+00:01:31,000 --> 00:01:39,000
+Is it the time package over time introduced in Java Version eight provides a comprehensive model for
+
+22
+00:01:39,000 --> 00:01:46,000
+date and time and was developed on the or 310 Date and time API.
+
+23
+00:01:46,000 --> 00:01:48,000
+The Jews are three hundred ten.
+
+24
+00:01:48,000 --> 00:01:57,000
+Design ensures that each method of the core API is able to fully define its input and output by focusing
+
+25
+00:01:57,000 --> 00:02:00,000
+the entire class on a single Calanda system.
+
+26
+00:02:00,000 --> 00:02:07,000
+Instead, users with advanced requirements have to study the API a little more closely and use the low
+
+27
+00:02:07,000 --> 00:02:11,000
+level temporal classes of Java.
+
+28
+00:02:11,000 --> 00:02:16,000
+Time is based on the International Organization for Standardization Calendar System.
+
+29
+00:02:16,000 --> 00:02:19,000
+Commonly used global calendars are also supported.
+
+30
+00:02:20,000 --> 00:02:30,000
+The API includes date and time, date without time, time without date offset from UTC Time Zone durations,
+
+31
+00:02:31,000 --> 00:02:36,000
+periods for Martin in person selection of calendar systems.
+
+32
+00:02:36,000 --> 00:02:42,000
+In order you could understand package structure easier, I recommend the group time related classes
+
+33
+00:02:42,000 --> 00:02:44,000
+into two categories.
+
+34
+00:02:45,000 --> 00:02:52,000
+We can classify dates and time into two basic use cases machine scale and human scale.
+
+35
+00:02:52,000 --> 00:02:59,000
+What is the difference and what classes in which group machine scale represents the passage of time
+
+36
+00:02:59,000 --> 00:03:03,000
+using a single, continually incremental number?
+
+37
+00:03:03,000 --> 00:03:09,000
+The rules that determine how the scale is measured and communicated are typically defined by international
+
+38
+00:03:09,000 --> 00:03:10,000
+scientific standards.
+
+39
+00:03:10,000 --> 00:03:18,000
+Organizations to create classes are defined to represent machine scale, time, instant and instant
+
+40
+00:03:18,000 --> 00:03:21,000
+on the timeline duration as a relation of time.
+
+41
+00:03:22,000 --> 00:03:24,000
+These classes use nanosecond precision.
+
+42
+00:03:25,000 --> 00:03:31,000
+The classes have sufficient accuracy to represent and in a second instant within the current age of
+
+43
+00:03:31,000 --> 00:03:37,000
+the universe, Unix epoch is used as a starting point for time calculation.
+
+44
+00:03:38,000 --> 00:03:45,000
+Human scale time represents the passage of time using a number of named fields such as the months they
+
+45
+00:03:46,000 --> 00:03:47,000
+hour, minute and second.
+
+46
+00:03:48,000 --> 00:03:53,000
+The rules that determine how the fields work together are defined in the calendar system.
+
+47
+00:03:54,000 --> 00:03:58,000
+The design adopted split the classes into value types and fields units.
+
+48
+00:03:59,000 --> 00:04:04,000
+The high level API contains four key classes, local date.
+
+49
+00:04:04,000 --> 00:04:05,000
+And that was no time.
+
+50
+00:04:05,000 --> 00:04:09,000
+Local time and time was no date, local date time.
+
+51
+00:04:10,000 --> 00:04:11,000
+This is daytime time.
+
+52
+00:04:12,000 --> 00:04:19,000
+These classes represent a time without a time zone in the ISO eighty six or one calendar system.
+
+53
+00:04:19,000 --> 00:04:23,000
+These classes don't store or represent a time zone.
+
+54
+00:04:24,000 --> 00:04:29,000
+Instead, it is a description of the local time as seen on a wall clock.
+
+55
+00:04:29,000 --> 00:04:36,000
+It can represent an instant on time line without additional information, such as an offset or time
+
+56
+00:04:36,000 --> 00:04:42,000
+zone in the classes above the masses that allow us to get the instance of the above mentioned times
+
+57
+00:04:42,000 --> 00:04:44,000
+with specific zone idea.
+
+58
+00:04:45,000 --> 00:04:51,000
+I believe you already familiar with zone idea from previous lesson, and you can understand that sometimes
+
+59
+00:04:51,000 --> 00:04:59,000
+you want to have times at account, time zone and fall classes has offset offset time at time and zone
+
+60
+00:04:59,000 --> 00:05:04,000
+offset with no date, offset the time and date time.
+
+61
+00:05:04,000 --> 00:05:12,000
+Offset its sawzall date and time fields the precision of nanoseconds, as well as the offset from Jeanne
+
+62
+00:05:12,000 --> 00:05:19,000
+to you to see, for example, the values that you can see on the slide next to offset time can be stored
+
+63
+00:05:19,000 --> 00:05:29,000
+in offset time zone data time at data time zone offset and time zone and data time with time zone is
+
+64
+00:05:29,000 --> 00:05:38,000
+the ISO eighty six 01 calendar system such as example shown next to zone time on the slide zone of SAT.
+
+65
+00:05:39,000 --> 00:05:47,000
+And I've said from the time and the GMT zone idea, a time zone identifier used to find the underlying
+
+66
+00:05:47,000 --> 00:05:47,000
+rules.
+
+67
+00:05:48,000 --> 00:05:55,000
+Each of these daytime classes represent time in the ISO calendar system defined by ISO eighty six one.
+
+68
+00:05:56,000 --> 00:06:03,000
+This is also known as a Prolacta Gregorian calendar system and is a de facto civil calendar system used
+
+69
+00:06:03,000 --> 00:06:06,000
+to date in the vast majority of the world.
+
+70
+00:06:06,000 --> 00:06:14,000
+Each day time field can be represented as a value which is expressed as a value of type long time in
+
+71
+00:06:14,000 --> 00:06:22,000
+milliseconds since Unix Epoch subfields also have an enum defined for koth clarity and safety.
+
+72
+00:06:22,000 --> 00:06:24,000
+This includes months.
+
+73
+00:06:24,000 --> 00:06:28,000
+There'll be a AMPM and quarter OSes.
+
+74
+00:06:28,000 --> 00:06:32,000
+There are loads of classes and each class has lots of matters.
+
+75
+00:06:32,000 --> 00:06:39,000
+The conceptual weight of the API is greatly reduced through consistent use of massive name prefixes.
+
+76
+00:06:40,000 --> 00:06:45,000
+That's why it will be easier for you to understand the API of new class in Java Time package if you
+
+77
+00:06:45,000 --> 00:06:49,000
+are really familiar with other class from the same package.
+
+78
+00:06:49,000 --> 00:06:54,000
+Some of the prefixes are get get the specified value.
+
+79
+00:06:54,000 --> 00:07:02,000
+Wisse, which has a copy of the object with a specified value change, for example, such as with our
+
+80
+00:07:02,000 --> 00:07:09,000
+Wissahickon that sets a specific value to a particular time unit plus minus returns a copy of the object
+
+81
+00:07:09,000 --> 00:07:16,000
+with a specified value added subtracted multiplied by divided by negated returns a copy of the object
+
+82
+00:07:16,000 --> 00:07:24,000
+with a specified value multiplied, divided, negated to convert the object to another related type
+
+83
+00:07:24,000 --> 00:07:26,000
+at which you object.
+
+84
+00:07:26,000 --> 00:07:35,000
+Considering of this date time as a specified argument acting as builder part of in mass that don't involve
+
+85
+00:07:35,000 --> 00:07:43,000
+data conversion from factory masses that do involve data conversion applications also commonly use a
+
+86
+00:07:43,000 --> 00:07:45,000
+temporal adjustment interface.
+
+87
+00:07:45,000 --> 00:07:52,000
+The standard implementations provided in temporal adjusters zis prepackaged common manipulation functions
+
+88
+00:07:52,000 --> 00:07:56,000
+like next Wednesday or the last day of the month.
+
+89
+00:07:56,000 --> 00:07:59,000
+They're specially available in captions.
+
+90
+00:07:59,000 --> 00:08:05,000
+The intent of the business logic, dates and time are formed from fields and units.
+
+91
+00:08:05,000 --> 00:08:07,000
+A unit is measurable.
+
+92
+00:08:07,000 --> 00:08:14,000
+Unit of time such as the months or hour is a set of known units can be extended by applications.
+
+93
+00:08:14,000 --> 00:08:21,000
+A field is used to express part of a larger the time, such as year, months of year.
+
+94
+00:08:22,000 --> 00:08:27,000
+A second of minutes is a set of known fields can also be extended by applications.
+
+95
+00:08:28,000 --> 00:08:34,000
+Now it is time to see the demo with some of these classes from Java Time package and understand how
+
+96
+00:08:34,000 --> 00:08:36,000
+to work with this classes on practice.
+
+97
+00:08:37,000 --> 00:08:42,000
+And we are going to start our examples from the super popular class from Java Time package.
+
+98
+00:08:42,000 --> 00:08:46,000
+I use it many times and I have seen other engineers use it very often.
+
+99
+00:08:47,000 --> 00:08:50,000
+We are going to start from instant class Java.
+
+100
+00:08:50,000 --> 00:08:54,000
+Instant Class is used to represent a specific moment on the timeline.
+
+101
+00:08:55,000 --> 00:08:59,000
+This might be used to record event time stamps in the application.
+
+102
+00:08:59,000 --> 00:09:06,000
+Like many other classes from Java Time package, this class is also immutable and safe.
+
+103
+00:09:06,000 --> 00:09:13,000
+Unlike the old Java till date, which has milliseconds, precision and instant has nanoseconds precision
+
+104
+00:09:14,000 --> 00:09:17,000
+representing a point in time using nanoseconds.
+
+105
+00:09:17,000 --> 00:09:21,000
+Precision requires the storage of a number larger than a loan.
+
+106
+00:09:22,000 --> 00:09:30,000
+To achieve this, the clusters alone represent an epoch seconds and an end to represent a nanosecond
+
+107
+00:09:30,000 --> 00:09:35,000
+of Saddam, which will always be between zero and Belan.
+
+108
+00:09:35,000 --> 00:09:43,000
+The seconds are measured from the standard Java epoch of January 1st one thousand nine hundred seventy,
+
+109
+00:09:43,000 --> 00:09:49,000
+where instance after the Epoch have positive Felis and other instances have negative fellus.
+
+110
+00:09:50,000 --> 00:09:51,000
+I open files.
+
+111
+00:09:51,000 --> 00:09:52,000
+It is called Instant Demo.
+
+112
+00:09:53,000 --> 00:09:56,000
+Let's start from how we can create instant object.
+
+113
+00:09:56,000 --> 00:10:01,000
+The different ways to do this very static mass that they can.
+
+114
+00:10:01,000 --> 00:10:04,000
+Different arguments may help us to instantiate instant.
+
+115
+00:10:04,000 --> 00:10:11,000
+Object here, a few examples with the help of now massive, an instance that is equal to the current
+
+116
+00:10:11,000 --> 00:10:20,000
+moment of time with the overloaded version of now mass as a text clock argument later in this class.
+
+117
+00:10:20,000 --> 00:10:26,000
+But just to let you know that you can pass any object of time to instantiate an object.
+
+118
+00:10:26,000 --> 00:10:33,000
+Also, the masses that allow us to create instant object is a four milliseconds or from seconds here
+
+119
+00:10:33,000 --> 00:10:38,000
+can see example of of approximately and of IPAC seconds massive.
+
+120
+00:10:39,000 --> 00:10:46,000
+Considering the fact that instant object has nanoseconds precision, you can be super accurate by specifying
+
+121
+00:10:46,000 --> 00:10:54,000
+an adjustment of seconds in the of seconds mass that you can pass to arguments, seconds and adjustment,
+
+122
+00:10:55,000 --> 00:10:58,000
+and also you can pass instant from three date.
+
+123
+00:10:58,000 --> 00:11:02,000
+Pay attention that there is a specific requirement to the format of the string.
+
+124
+00:11:03,000 --> 00:11:10,000
+The string must represent a valid instant in the U.S. and is past using date time for Martha.
+
+125
+00:11:10,000 --> 00:11:12,000
+So instant constant.
+
+126
+00:11:12,000 --> 00:11:15,000
+Besides that, you already know Jamie till date class.
+
+127
+00:11:16,000 --> 00:11:20,000
+That class has methods that allow us to convert date to instant.
+
+128
+00:11:20,000 --> 00:11:26,000
+So just called the instant method and you will get reference to the instant object that is equivalent
+
+129
+00:11:26,000 --> 00:11:27,000
+to the date one.
+
+130
+00:11:28,000 --> 00:11:33,000
+And it is also worth dimensions that we can convert values into directions.
+
+131
+00:11:33,000 --> 00:11:36,000
+For example, I can easily convert instant to milliseconds.
+
+132
+00:11:37,000 --> 00:11:38,000
+Here is an example.
+
+133
+00:11:38,000 --> 00:11:41,000
+The epitome of the method returns as milliseconds.
+
+134
+00:11:42,000 --> 00:11:43,000
+Let's move on.
+
+135
+00:11:43,000 --> 00:11:50,000
+An instant object contains two fields internally, which holds the time represented by the instant seconds
+
+136
+00:11:50,000 --> 00:11:56,000
+since the epoch and nanoseconds part of the instant, which is less than one second.
+
+137
+00:11:57,000 --> 00:12:02,000
+We can access both the seconds and nanoseconds we as these masses get.
+
+138
+00:12:03,000 --> 00:12:10,000
+Second, get the number of seconds from the Java Epoch and get Nonno, get the number of nanoseconds
+
+139
+00:12:11,000 --> 00:12:14,000
+later along the timeline from the start of the second.
+
+140
+00:12:14,000 --> 00:12:19,000
+And also there is another way to extract is a seconds or nanoseconds.
+
+141
+00:12:19,000 --> 00:12:21,000
+You can extract the value you need.
+
+142
+00:12:21,000 --> 00:12:26,000
+We are getting get long message that takes on a field as an argument.
+
+143
+00:12:27,000 --> 00:12:31,000
+Crowninshield Enum contains different constants and dependent on the API.
+
+144
+00:12:31,000 --> 00:12:34,000
+You can use it with different classes in Java Time package.
+
+145
+00:12:35,000 --> 00:12:39,000
+Pay attention that in this particular case was instant object.
+
+146
+00:12:39,000 --> 00:12:43,000
+Not all fields from a field in an unsupported.
+
+147
+00:12:43,000 --> 00:12:49,000
+If you try to get one of unsupported field, you will get for an error unsupported temporal type of
+
+148
+00:12:49,000 --> 00:12:51,000
+section unsupported field.
+
+149
+00:12:52,000 --> 00:12:58,000
+The instant class also has several masses which can be used to do add, subtract operations.
+
+150
+00:12:58,000 --> 00:13:06,000
+Let's review these masses minus the takes amount to subtract and temporal unit returns.
+
+151
+00:13:06,000 --> 00:13:13,000
+A copy of this instance, with a specified amount subtracted and minus was just amount to subtract returns.
+
+152
+00:13:13,000 --> 00:13:16,000
+A copy of this instance was a specified amount subtracted.
+
+153
+00:13:17,000 --> 00:13:19,000
+Usually duration is used here.
+
+154
+00:13:19,000 --> 00:13:23,000
+We are going to learn how to work with duration later in this lesson.
+
+155
+00:13:24,000 --> 00:13:31,000
+So you can see two types here that are used in mass parameters, temporal unit and temporal amount.
+
+156
+00:13:32,000 --> 00:13:34,000
+There is a package of time temporal.
+
+157
+00:13:35,000 --> 00:13:37,000
+What kind of types are grouped in this package?
+
+158
+00:13:38,000 --> 00:13:46,000
+This package contains types that ensures access to date and time using fields and units and daytime
+
+159
+00:13:46,000 --> 00:13:47,000
+justice.
+
+160
+00:13:47,000 --> 00:13:54,000
+This package expands on the base package to provide additional functionality for more powerful use cases.
+
+161
+00:13:55,000 --> 00:14:03,000
+Support is included for the units of daytime, such as years, months, days and hours fields of the
+
+162
+00:14:03,000 --> 00:14:05,000
+time, such as months of year.
+
+163
+00:14:05,000 --> 00:14:13,000
+They will be out of the date time adjustment functions, different definitions of the temporal unit
+
+164
+00:14:13,000 --> 00:14:21,000
+that describes a unit of a date time, such as days or hours, temporal amount, framework, level interface
+
+165
+00:14:21,000 --> 00:14:27,000
+define an amount of time such as six hours a day or two years and three months.
+
+166
+00:14:27,000 --> 00:14:34,000
+As we look through the API of Java Time package, you would notice that we are using different temporalis.
+
+167
+00:14:35,000 --> 00:14:42,000
+So I would also recommend you to open documentation of Java Time temporal package to review other types
+
+168
+00:14:42,000 --> 00:14:42,000
+declared.
+
+169
+00:14:42,000 --> 00:14:51,000
+There are the mass that allows us to perform at subtract operations are minus minus minus minus minus
+
+170
+00:14:51,000 --> 00:14:51,000
+seconds.
+
+171
+00:14:51,000 --> 00:14:56,000
+I believe you are smart enough already to understand what this is about by their names.
+
+172
+00:14:57,000 --> 00:15:04,000
+And we have similar plus masses with temporal unit and temporal amount plus minus plus minus.
+
+173
+00:15:04,000 --> 00:15:11,000
+The seconds have separate method here, as it is called at subtract them, you can find different code
+
+174
+00:15:11,000 --> 00:15:12,000
+examples here.
+
+175
+00:15:12,000 --> 00:15:16,000
+I just want to draw your attention to one single temporal temperament.
+
+176
+00:15:16,000 --> 00:15:19,000
+Interface has different implementations.
+
+177
+00:15:19,000 --> 00:15:25,000
+And here we are, for example, with duration and period, these implementations of temporal amount.
+
+178
+00:15:26,000 --> 00:15:28,000
+These classes have pretty intuitive API.
+
+179
+00:15:29,000 --> 00:15:35,000
+I believe once you understand how to work with instant objects, it will be super easy to understand
+
+180
+00:15:35,000 --> 00:15:37,000
+how to work with those classes.
+
+181
+00:15:38,000 --> 00:15:44,000
+Sometimes you need to compare to moments of time, the separate method here that is coded comparison.
+
+182
+00:15:44,000 --> 00:15:48,000
+I'm going to show you examples of how you can compare two moments in time.
+
+183
+00:15:48,000 --> 00:15:55,000
+Instant class also has an intuitive interface for this machine that we have two instant objects and
+
+184
+00:15:55,000 --> 00:16:01,000
+one of instant objects describes a moment in time that is before of another one.
+
+185
+00:16:01,000 --> 00:16:02,000
+Just for one second.
+
+186
+00:16:03,000 --> 00:16:10,000
+We have masses is after and is before to understand which instant goes first can console output.
+
+187
+00:16:10,000 --> 00:16:14,000
+You can see that we received logically correct results.
+
+188
+00:16:14,000 --> 00:16:20,000
+Instant one goes prior to instant two also instant implements, comparable interface.
+
+189
+00:16:21,000 --> 00:16:24,000
+That's why we can use compared to method for comparison.
+
+190
+00:16:24,000 --> 00:16:31,000
+Just to remind you, this message returns negative, positive and zero values to answer the question
+
+191
+00:16:31,000 --> 00:16:35,000
+which object should go before and which object should go after?
+
+192
+00:16:35,000 --> 00:16:36,000
+Unions are sorted.
+
+193
+00:16:37,000 --> 00:16:44,000
+By the way, the similar way you can compare to colanders can object has such mass as after and before.
+
+194
+00:16:45,000 --> 00:16:51,000
+And here you can see a result of comparison similar to the instant type calendar is also comparable
+
+195
+00:16:51,000 --> 00:16:53,000
+time and has compared to Massett.
+
+196
+00:16:54,000 --> 00:17:00,000
+But you already saw an instant example how you can use compared to Mass and you won't believe me.
+
+197
+00:17:01,000 --> 00:17:08,000
+But Jaballah till date class uses a similar naming convention for masses to compare to this also with
+
+198
+00:17:08,000 --> 00:17:10,000
+your date implements comparable interface.
+
+199
+00:17:11,000 --> 00:17:19,000
+Thus it also has compared to the next example, shows us how we can easily convert the instant object
+
+200
+00:17:19,000 --> 00:17:22,000
+to objects of another Tibs from our time package.
+
+201
+00:17:22,000 --> 00:17:29,000
+I know that this is crazy number of classes to represent one date, but this is Gever and sometimes
+
+202
+00:17:29,000 --> 00:17:35,000
+depending on the code you're working with or integrating ways, you might need to convert objects to
+
+203
+00:17:35,000 --> 00:17:40,000
+different types in order you could use existing API, for example.
+
+204
+00:17:41,000 --> 00:17:49,000
+In this example, you can see how we can convert instant to local Data Zonday time and offset the time,
+
+205
+00:17:49,000 --> 00:17:54,000
+I believe that we have learned about in some type really a lot already.
+
+206
+00:17:54,000 --> 00:17:58,000
+Let's review the next class that I've learned to review with you today.
+
+207
+00:17:58,000 --> 00:18:01,000
+Urines review of the following classes.
+
+208
+00:18:01,000 --> 00:18:08,000
+I will be a little bit faster because as I said at the beginning of the lesson, the API in Java package
+
+209
+00:18:08,000 --> 00:18:09,000
+is standardised.
+
+210
+00:18:09,000 --> 00:18:13,000
+We have methods with similar names that follow a similar pattern.
+
+211
+00:18:14,000 --> 00:18:19,000
+So during the review of the class, I will focus your attention only on the important things that are
+
+212
+00:18:19,000 --> 00:18:27,000
+different from other classes I open local, the time Democrats local, the time class represents at
+
+213
+00:18:27,000 --> 00:18:32,000
+the time without a time zone in the ISO eighty six or one column.
+
+214
+00:18:32,000 --> 00:18:37,000
+The system such as example you see often viewed as Yemens Day.
+
+215
+00:18:37,000 --> 00:18:42,000
+Our minus second time is represented the Marsac and Precision.
+
+216
+00:18:43,000 --> 00:18:49,000
+We can simply say that local daytime class is a combination of the local data and local time class.
+
+217
+00:18:50,000 --> 00:18:57,000
+This class is immutable and safe and the whole separate overview of local data local time.
+
+218
+00:18:57,000 --> 00:19:03,000
+Because in my opinion then the reason to make this lesson even longer, because once we review local
+
+219
+00:19:04,000 --> 00:19:06,000
+time, our will become clear for you.
+
+220
+00:19:07,000 --> 00:19:14,000
+And in practice, most often you use daytime classes instead of just using time without date or date
+
+221
+00:19:14,000 --> 00:19:14,000
+without time.
+
+222
+00:19:15,000 --> 00:19:19,000
+So let's start from the sense that a common was in some class.
+
+223
+00:19:19,000 --> 00:19:24,000
+Similar matters for comparison I'm talking about is after and is before.
+
+224
+00:19:25,000 --> 00:19:27,000
+In case you want to compare to local daytime objects.
+
+225
+00:19:28,000 --> 00:19:30,000
+Similar way to add and subtract time.
+
+226
+00:19:31,000 --> 00:19:34,000
+You have Masad plus minus with different list of arguments.
+
+227
+00:19:35,000 --> 00:19:43,000
+And considering is local daytime, you can also add and subtract all the time units like these hours,
+
+228
+00:19:43,000 --> 00:19:51,000
+minutes, months, weeks, years, similar way to instantiate local data and object of mass that is
+
+229
+00:19:51,000 --> 00:19:57,000
+overloaded with possibility to pass different time units in comparison with in some class you can pass
+
+230
+00:19:57,000 --> 00:20:03,000
+the Mancia our minutes second nanosecond and different variations and combinations of these.
+
+231
+00:20:04,000 --> 00:20:12,000
+Instantiation, here's an example, you can find source code examples of local daytime instantiation,
+
+232
+00:20:12,000 --> 00:20:19,000
+and once you instantiate objects, you can work with data that it contains Inmarsat getting information.
+
+233
+00:20:19,000 --> 00:20:26,000
+Example, you can find a lot of source code examples of how you can extract different values from local
+
+234
+00:20:26,000 --> 00:20:30,000
+daytime object, as you can notice from method names.
+
+235
+00:20:30,000 --> 00:20:34,000
+It is clear what type of unit value I want to extract and leave.
+
+236
+00:20:34,000 --> 00:20:41,000
+So and as a matter that is called add, subtract time example, you can find good examples of how to
+
+237
+00:20:41,000 --> 00:20:44,000
+add and subtract different time units from local daytime object.
+
+238
+00:20:45,000 --> 00:20:48,000
+You can find the source code in attachments to this lesson.
+
+239
+00:20:49,000 --> 00:20:54,000
+I will not stop on this since the explanation is similar to what we have discussed during the review
+
+240
+00:20:54,000 --> 00:20:58,000
+of Instant Class explores the source code examples by yourself.
+
+241
+00:20:58,000 --> 00:21:05,000
+If you are interested and ask your questions and comments if you have any, let's continue the next
+
+242
+00:21:05,000 --> 00:21:14,000
+class to review isn't the time I open zoned daytime demo class zoned the class represents a daytime
+
+243
+00:21:14,000 --> 00:21:17,000
+was a time zone in the ISO eighty six.
+
+244
+00:21:17,000 --> 00:21:24,000
+So until the system such as example you can see on the screen this class is immutable and safe.
+
+245
+00:21:24,000 --> 00:21:32,000
+Stores all date and time fields the precision of nanoseconds and time zone was a zone of sat used to
+
+246
+00:21:32,000 --> 00:21:38,000
+handle ambiguous local daytime's have for example, of instantiation of zone data an object.
+
+247
+00:21:39,000 --> 00:21:45,000
+To be honest, the naming convention of factory masses is similar to other classes we have reviewed.
+
+248
+00:21:45,000 --> 00:21:48,000
+The only difference probabilities of strict math.
+
+249
+00:21:49,000 --> 00:21:56,000
+This method obtains an instance of zoned daytime strictly validated that combination of local daytime
+
+250
+00:21:56,000 --> 00:21:58,000
+offset and Zinaida.
+
+251
+00:21:58,000 --> 00:22:05,000
+This creates as zoned daytime insurance as the offset is valid for the local daytime, according to
+
+252
+00:22:05,000 --> 00:22:07,000
+the rules of the specified zone.
+
+253
+00:22:08,000 --> 00:22:12,000
+If the offset is invalid, an exception is thrown.
+
+254
+00:22:12,000 --> 00:22:19,000
+Once regretted object of zoned daytime, we can work with it and extract any data that we need in the
+
+255
+00:22:19,000 --> 00:22:21,000
+mass at get information example.
+
+256
+00:22:21,000 --> 00:22:27,000
+You can find examples of interaction with zoned daytime object in Oza masses.
+
+257
+00:22:27,000 --> 00:22:29,000
+That is called conversion example.
+
+258
+00:22:29,000 --> 00:22:36,000
+You can find the ways how to convert the sound, the time to other objects, namely to EPOXI, to instance,
+
+259
+00:22:37,000 --> 00:22:42,000
+to local date, the local daytime, the local time, and to offset the time.
+
+260
+00:22:42,000 --> 00:22:48,000
+And also similar to the previous example, I have got examples here of add subtract operations.
+
+261
+00:22:48,000 --> 00:22:50,000
+You can check, add, subtract time.
+
+262
+00:22:50,000 --> 00:22:51,000
+Example Massett.
+
+263
+00:22:52,000 --> 00:23:01,000
+Now let's quickly review offset daytime time type I open offset the time Democrats offset the time class
+
+264
+00:23:01,000 --> 00:23:08,000
+represents a date time with an offset from UTC Green which in the ISO eighty six or one count on the
+
+265
+00:23:08,000 --> 00:23:10,000
+system such as example.
+
+266
+00:23:10,000 --> 00:23:18,000
+You can see on the screen this class is immutable and save offset the time zone, daytime and instant
+
+267
+00:23:19,000 --> 00:23:21,000
+store and instant on the time line.
+
+268
+00:23:21,000 --> 00:23:26,000
+The nanosecond precision instant is the simplest.
+
+269
+00:23:26,000 --> 00:23:31,000
+Simply representing to offset the time adds to the instance.
+
+270
+00:23:31,000 --> 00:23:39,000
+The offset from UTC in which which allows the local time to be obtained, isn't the time at full time
+
+271
+00:23:39,000 --> 00:23:40,000
+zone rules.
+
+272
+00:23:41,000 --> 00:23:47,000
+It is intended that Zonday time or instant is used to model data in simpler applications.
+
+273
+00:23:48,000 --> 00:23:55,000
+Offset date time may be used when more than date time concepts in more detail or when communicating
+
+274
+00:23:55,000 --> 00:24:02,000
+through database or in the network protocol similar to all previous classes reviewed in this file,
+
+275
+00:24:02,000 --> 00:24:09,000
+you can find examples of different ways of instantiation, of objects of this type working with the
+
+276
+00:24:09,000 --> 00:24:13,000
+object conversion example and add subtract time example.
+
+277
+00:24:13,000 --> 00:24:18,000
+Also in this lesson, I would like to have a review of such class escalope.
+
+278
+00:24:18,000 --> 00:24:26,000
+Let me open the source code of class a clock providing access to the current instant date and time using
+
+279
+00:24:26,000 --> 00:24:29,000
+a time zone instances of this class.
+
+280
+00:24:29,000 --> 00:24:36,000
+I used to find the current instant which can be interpreted using the stored time zone to find the current
+
+281
+00:24:36,000 --> 00:24:37,000
+date and time.
+
+282
+00:24:38,000 --> 00:24:45,000
+As such, a clock can be used instead of system continuous mass communication and time zone.
+
+283
+00:24:45,000 --> 00:24:51,000
+Yet default mass use of a clock object is optional or key.
+
+284
+00:24:51,000 --> 00:24:58,000
+Daytime classes also have and now factor in mass that uses a system clock and the default time zone.
+
+285
+00:24:59,000 --> 00:25:03,000
+The primary purpose of this abstraction is to allow alternate clocks to.
+
+286
+00:25:04,000 --> 00:25:12,000
+The plugged in as and when required applications use an object to obtain the current time as an aesthetic
+
+287
+00:25:12,000 --> 00:25:12,000
+method.
+
+288
+00:25:13,000 --> 00:25:14,000
+This can simplify testing.
+
+289
+00:25:15,000 --> 00:25:22,000
+Best practice for applications is to look into any Massachusetts request, the current instant, the
+
+290
+00:25:22,000 --> 00:25:29,000
+current date and time, depending on the time zone and globalized applications that the provider is
+
+291
+00:25:29,000 --> 00:25:35,000
+necessary to ensure as a date and time are created with the correct time zone.
+
+292
+00:25:35,000 --> 00:25:43,000
+This class helps us to test that our chord changes work with different time zones or when using a fixed
+
+293
+00:25:43,000 --> 00:25:46,000
+clock, the time doesn't affect our code.
+
+294
+00:25:47,000 --> 00:25:54,000
+As we already set the clock class is observed and you can't create instances of abstract type.
+
+295
+00:25:54,000 --> 00:26:00,000
+But this gloss declares factory maps that allow to instantiate objects of this type.
+
+296
+00:26:00,000 --> 00:26:04,000
+I would like to name just some popular ones that might come in handy.
+
+297
+00:26:05,000 --> 00:26:12,000
+Offset mass of the text based clock object as the first Masset argument and duration object as a second
+
+298
+00:26:12,000 --> 00:26:12,000
+argument.
+
+299
+00:26:13,000 --> 00:26:18,000
+This method returns a clock that is offset by the specified duration.
+
+300
+00:26:19,000 --> 00:26:25,000
+Main use case for this is to simulate running in the future or the past system.
+
+301
+00:26:25,000 --> 00:26:32,000
+You see this massive just returns the clock representing the UTC time zone fixed mass.
+
+302
+00:26:32,000 --> 00:26:37,000
+The text to arguments instant and Zinaida always return the same instant.
+
+303
+00:26:38,000 --> 00:26:46,000
+The leading use case for this is in testing, whereas a fixed clock ensures that does not depend on
+
+304
+00:26:46,000 --> 00:26:48,000
+the current clock during the.
+
+305
+00:26:48,000 --> 00:26:53,000
+Today we are also going to review ASRM assets to instantiate the object.
+
+306
+00:26:54,000 --> 00:26:56,000
+Let me now open them across.
+
+307
+00:26:57,000 --> 00:27:02,000
+Here in the class, you will be able to find different examples how to instantiate Klok object.
+
+308
+00:27:03,000 --> 00:27:09,000
+Basically, the different facts of a mass like system default zone System UTC is that we have already
+
+309
+00:27:09,000 --> 00:27:14,000
+removed system mass of the text zone idea as a method argument.
+
+310
+00:27:14,000 --> 00:27:19,000
+Look for that zone and here's a simple example was fixed factor.
+
+311
+00:27:19,000 --> 00:27:27,000
+Massell, I can tell you from my experience, clock class is really helpful, especially during the
+
+312
+00:27:27,000 --> 00:27:31,000
+unit testing when you need to simulate some specific moment of time.
+
+313
+00:27:32,000 --> 00:27:39,000
+And here you can see that I can get milliseconds by calling me this massive, also superimportant for
+
+314
+00:27:39,000 --> 00:27:40,000
+testing purposes.
+
+315
+00:27:41,000 --> 00:27:49,000
+If you need to imitate some time offset, you can call offset Masset and pass base, clock and duration
+
+316
+00:27:49,000 --> 00:27:50,000
+to make time offset.
+
+317
+00:27:51,000 --> 00:27:57,000
+Check those examples and remember, in case something stays unclear and you can't understand something,
+
+318
+00:27:58,000 --> 00:28:01,000
+you're always welcome to ask questions and comments to this video.
+
+319
+00:28:02,000 --> 00:28:08,000
+I will be happy to answer your questions and the last but not the least two classes that we are going
+
+320
+00:28:08,000 --> 00:28:10,000
+to learn today, period and duration.
+
+321
+00:28:11,000 --> 00:28:17,000
+Both classes can be used to represent an amount of time on the timelines, a difference between two
+
+322
+00:28:17,000 --> 00:28:18,000
+dates.
+
+323
+00:28:18,000 --> 00:28:26,000
+The main distinction between the two classes is that period uses date based values, while duration
+
+324
+00:28:26,000 --> 00:28:28,000
+uses time based values.
+
+325
+00:28:28,000 --> 00:28:35,000
+Also small, but important to note is that durations and periods differ in their treatment of daylight
+
+326
+00:28:35,000 --> 00:28:42,000
+saving time, when added to the time and duration, will add an exact number of seconds.
+
+327
+00:28:43,000 --> 00:28:48,000
+Thus, a duration of one day is always exactly twenty four hours.
+
+328
+00:28:48,000 --> 00:28:54,000
+By contrast, a period that will, at a conceptual day, trying to maintain the local time.
+
+329
+00:28:55,000 --> 00:29:00,000
+The support units of a period are years, months and days.
+
+330
+00:29:00,000 --> 00:29:04,000
+All three fields are always present, but may be set to zero.
+
+331
+00:29:04,000 --> 00:29:07,000
+Let me now perform an overview of duration class.
+
+332
+00:29:08,000 --> 00:29:16,000
+This class model, a quantity or amount of time in terms of seconds and not a seconds, it can be accessed
+
+333
+00:29:16,000 --> 00:29:20,000
+using other duration based units, such as minutes and hours.
+
+334
+00:29:20,000 --> 00:29:27,000
+In addition, the decision can be used and is treated as exactly equal to twenty four hours.
+
+335
+00:29:27,000 --> 00:29:33,000
+Like I've already mentioned, the range of a duration requires the storage of a number larger than the
+
+336
+00:29:33,000 --> 00:29:34,000
+long.
+
+337
+00:29:34,000 --> 00:29:41,000
+To achieve this, the clusters along represented seconds and an end to represent a nanosecond of second.
+
+338
+00:29:42,000 --> 00:29:44,000
+The duration may be negative.
+
+339
+00:29:44,000 --> 00:29:47,000
+I believe this is enough for an overview.
+
+340
+00:29:47,000 --> 00:29:51,000
+Let's jump to a source code examples I open period demo class.
+
+341
+00:29:52,000 --> 00:29:55,000
+Imagine that you need to calculate the difference between today's.
+
+342
+00:29:56,000 --> 00:29:58,000
+I don't know the reason why I need this.
+
+343
+00:29:58,000 --> 00:30:03,000
+For example, there is a special promotional offers that is applicable only if you buy.
+
+344
+00:30:03,000 --> 00:30:10,000
+Within the same period after your last purchase, anyway, you might have different reasons for that
+
+345
+00:30:10,000 --> 00:30:13,000
+and business class may help us to calculate this.
+
+346
+00:30:13,000 --> 00:30:18,000
+You call static mass between and past due dates to the matter.
+
+347
+00:30:18,000 --> 00:30:25,000
+As a result, you receive the reference to the direct object, which you can use to extract specific
+
+348
+00:30:25,000 --> 00:30:29,000
+years, months and days that passed between these two dates.
+
+349
+00:30:30,000 --> 00:30:37,000
+Does this make sense in case you need to create beareth object to pass to OSM assets like we have already
+
+350
+00:30:37,000 --> 00:30:44,000
+saw in examples today you can use static of method and methods for specific time units like you see
+
+351
+00:30:44,000 --> 00:30:45,000
+in this example.
+
+352
+00:30:46,000 --> 00:30:50,000
+You can create a period from days, months, years and weeks.
+
+353
+00:30:50,000 --> 00:30:57,000
+Also another way to get period object, which I can say didn't use very often, but still it is possible
+
+354
+00:30:57,000 --> 00:31:01,000
+to use it to is to purse string.
+
+355
+00:31:01,000 --> 00:31:05,000
+But then there is a specific role for string to the past.
+
+356
+00:31:05,000 --> 00:31:13,000
+You can open documentation for past Masset in period class to find rules that should be basically you
+
+357
+00:31:13,000 --> 00:31:20,000
+need to specify P for period after that number of units and first letter of the time unit.
+
+358
+00:31:20,000 --> 00:31:25,000
+If you need a period of two years, you just write P to Y.
+
+359
+00:31:25,000 --> 00:31:31,000
+If you need a period of three months, you just write B three M and that's it.
+
+360
+00:31:32,000 --> 00:31:32,000
+Is this clear?
+
+361
+00:31:33,000 --> 00:31:34,000
+Great.
+
+362
+00:31:34,000 --> 00:31:35,000
+Let me open duration demo.
+
+363
+00:31:35,000 --> 00:31:42,000
+Now, similar to the previous example, you can get the difference between two moments in time, but
+
+364
+00:31:42,000 --> 00:31:48,000
+take into account this is a duration object you can extract with getas seconds, values, minutes,
+
+365
+00:31:49,000 --> 00:31:51,000
+hours and nanoseconds of the second.
+
+366
+00:31:52,000 --> 00:31:54,000
+And that's a way to instantiate duration.
+
+367
+00:31:54,000 --> 00:32:01,000
+Object is to use of MassArt the different variations of this method of seconds, of minutes, of hours,
+
+368
+00:32:01,000 --> 00:32:04,000
+of days of millions of us here.
+
+369
+00:32:04,000 --> 00:32:12,000
+An example I showed just two examples of this method and ways of ours method similar to the example
+
+370
+00:32:12,000 --> 00:32:13,000
+we saw during that period demo.
+
+371
+00:32:14,000 --> 00:32:22,000
+We can pass duration from string and again the specific requirements to the string in the documentation
+
+372
+00:32:22,000 --> 00:32:22,000
+of the past.
+
+373
+00:32:22,000 --> 00:32:24,000
+Measured from duration clause.
+
+374
+00:32:24,000 --> 00:32:26,000
+You can always check examples and rules.
+
+375
+00:32:26,000 --> 00:32:29,000
+Even you accidentally forgot what the part is.
+
+376
+00:32:30,000 --> 00:32:32,000
+That's what I wanted to share with you for the day.
+
+377
+00:32:33,000 --> 00:32:35,000
+Let's recap what we have learned in this lesson.
+
+378
+00:32:36,000 --> 00:32:42,000
+We hold an overview of Java Time package and I introduce type classifications that are supposed to help
+
+379
+00:32:42,000 --> 00:32:46,000
+you to lower classes, groups of them and how they're different.
+
+380
+00:32:47,000 --> 00:32:51,000
+After that, we have different classes to work with, date and time.
+
+381
+00:32:51,000 --> 00:32:59,000
+They are instant local, the time zone, the time offset data, the round clock time.
+
+382
+00:33:00,000 --> 00:33:07,000
+And at the end of the lesson I explained how to work with spirit and duration classes while just seeing
+
+383
+00:33:07,000 --> 00:33:08,000
+how much we have learned today.
+
+384
+00:33:09,000 --> 00:33:13,000
+Now you can work with dates and time in Java like a pro, believe me.
+
+385
+00:33:14,000 --> 00:33:15,000
+That's it for this lesson.
+
+386
+00:33:16,000 --> 00:33:17,000
+Thank you for your attention.
+
+387
+00:33:17,000 --> 00:33:20,000
+Have a great day and see you in the next lesson.
+
diff --git a/29 - Date and Time in JDK/003 Quiz Date and Time in Java - Check yourself.html b/29 - Date and Time in JDK/003 Quiz Date and Time in Java - Check yourself.html
new file mode 100644
index 0000000000000000000000000000000000000000..a16d864935bc07dafa2ed37a84a6157a1ecd8519
--- /dev/null
+++ b/29 - Date and Time in JDK/003 Quiz Date and Time in Java - Check yourself.html
@@ -0,0 +1,69 @@
+
+
+
+
+
+ Quiz Date and Time in Java - Check yourself
+
+
+
+
+
+
+
Quiz Date and Time in Java - Check yourself
+
Quiz Link: https://forms.gle/X5NHAix9Rmph5vvJA
The quiz doesn’t require you to log in or submit any personal information. Your data privacy is my priority.
The Quiz covers content from the following lessons:
Time Standards (GMT, UTC), Date and Calendar from java.util
java.time Package (Instant, LocalDateTime, ZonedDateTime etc)
Quiz Instructions:
This quiz is designed to help you check your understanding of the content from the previous lessons. All questions are based only on material covered in the lessons you've already watched, so there’s no need to worry about unfamiliar topics.
Each question has one correct answer. Select the best answer and click "Submit" when you're ready.
After submitting, you'll see your score. For each question, you earn 1 point.
Click "View Results" to see the explanations for each correct answer. Reviewing these explanations can help reinforce your understanding.
If you score below 70%, I recommend revisiting the previous lessons. However, if the explanations make sense and you’re confident in your understanding, feel free to move on.
If any explanations are unclear, please don’t hesitate to post questions in the Q&A section—I’m here to help!
+
+
+
+
diff --git a/29 - Date and Time in JDK/external-links.txt b/29 - Date and Time in JDK/external-links.txt
new file mode 100644
index 0000000000000000000000000000000000000000..5d28fe3c4f98df90f0a41594fe535d73de99f36e
--- /dev/null
+++ b/29 - Date and Time in JDK/external-links.txt
@@ -0,0 +1,6 @@
+
+001 Source-code-of-example-from-the-lesson
+https://github.com/AndriiPiatakha/learnit_java_core/blob/master/src/com/itbulls/learnit/javacore/date/Demo.java
+
+002 Source-code-of-examples-from-the-lesson
+https://github.com/AndriiPiatakha/learnit_java_core/tree/master/src/com/itbulls/learnit/javacore/date
diff --git a/30 - Java Reflection API/001 Java Reflection API_en.srt b/30 - Java Reflection API/001 Java Reflection API_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..897b8d99b48c4c8ecb5c865371c7f3566117ad4a
--- /dev/null
+++ b/30 - Java Reflection API/001 Java Reflection API_en.srt
@@ -0,0 +1,1360 @@
+1
+00:00:05,000 --> 00:00:06,000
+Hello, Jim.
+
+2
+00:00:06,000 --> 00:00:12,000
+In this lesson, we're going to learn a really interesting topic that is Skulled Jallow Reflexion API.
+
+3
+00:00:12,000 --> 00:00:18,000
+We have a lot of things to learn today, but as usual, we're going to start from Seery and Grado.
+
+4
+00:00:18,000 --> 00:00:20,000
+It will get to the code examples.
+
+5
+00:00:20,000 --> 00:00:23,000
+So it's the beginning of the lesson we're going to learn.
+
+6
+00:00:23,000 --> 00:00:31,000
+What a reflection API is and what rules does adapt will review Java like reflect package in order,
+
+7
+00:00:31,000 --> 00:00:34,000
+you know, where you can look for the official documentation.
+
+8
+00:00:35,000 --> 00:00:37,000
+And after that, we will start our protocol.
+
+9
+00:00:37,000 --> 00:00:43,000
+Part of the lesson I'm going to show you how you can grow up with different class entities such as fields,
+
+10
+00:00:43,000 --> 00:00:45,000
+constructors, mass interfaces.
+
+11
+00:00:45,000 --> 00:00:48,000
+Superclusters was a help of reflection API.
+
+12
+00:00:49,000 --> 00:00:55,000
+I will put special focus on a separate group of examples that relates to the work with private entities
+
+13
+00:00:55,000 --> 00:00:56,000
+inside the class.
+
+14
+00:00:57,000 --> 00:01:00,000
+As I already said, there will be a lot of interesting things.
+
+15
+00:01:01,000 --> 00:01:07,000
+Believe me, this will be mind blowing when you understand what you can do with the help of Reflection
+
+16
+00:01:07,000 --> 00:01:07,000
+API.
+
+17
+00:01:08,000 --> 00:01:09,000
+So let's start our lesson.
+
+18
+00:01:10,000 --> 00:01:16,000
+And to start with, let's understand first what's reflexion is one of reflection is used and why do
+
+19
+00:01:16,000 --> 00:01:17,000
+we need it?
+
+20
+00:01:18,000 --> 00:01:25,000
+Reflection is a commonly used by programs which requires and devoted to X in line or modifies the runtime
+
+21
+00:01:25,000 --> 00:01:28,000
+behavior of applications running into Java virtual machine.
+
+22
+00:01:29,000 --> 00:01:36,000
+In other words, Reflection API allows us to inspect or modify attributes of classis interfaces, fields
+
+23
+00:01:36,000 --> 00:01:38,000
+and masses, duendes of program execution.
+
+24
+00:01:38,000 --> 00:01:42,000
+That's a runtime that is basically after the compilation process.
+
+25
+00:01:42,000 --> 00:01:43,000
+How would you like it?
+
+26
+00:01:43,000 --> 00:01:44,000
+Tolerate it?
+
+27
+00:01:44,000 --> 00:01:52,000
+Additionally, we can instantiate new objects, invoke methods and get a set feel to values using reflection.
+
+28
+00:01:52,000 --> 00:01:56,000
+Even if Zapp Private Fields and Zendō Gatsas or satyrs.
+
+29
+00:01:57,000 --> 00:02:04,000
+Probably you will not implement codes are related to reflection on daily basis, but 100 percent you
+
+30
+00:02:04,000 --> 00:02:09,000
+will deal with code that uses reflection inside such libraries as Jeunet.
+
+31
+00:02:09,000 --> 00:02:15,000
+Marqueta is Imark Power, Mock Sprink framework and many others.
+
+32
+00:02:15,000 --> 00:02:18,000
+All of them use elements of reflection API.
+
+33
+00:02:19,000 --> 00:02:25,000
+But as a consumer of the search party library, you just sanjoy and its features without implementing
+
+34
+00:02:25,000 --> 00:02:26,000
+your own version of G unit.
+
+35
+00:02:27,000 --> 00:02:27,000
+Correct.
+
+36
+00:02:28,000 --> 00:02:32,000
+That's why you need to know what's the function is and how to work with it.
+
+37
+00:02:32,000 --> 00:02:39,000
+This is relatively advanced feature and should be used only by developers who have a strong grasp of
+
+38
+00:02:39,000 --> 00:02:43,000
+fundamentals of the language with that caveat in mind.
+
+39
+00:02:43,000 --> 00:02:50,000
+Reflection is a powerful technique and can enable applications to perform operations which would otherwise
+
+40
+00:02:50,000 --> 00:02:51,000
+be impossible.
+
+41
+00:02:52,000 --> 00:02:55,000
+And what are the cases when we need the reflection API?
+
+42
+00:02:56,000 --> 00:03:02,000
+Yeah, various cases when we need to use this API to achieve certain result that we provided was just
+
+43
+00:03:02,000 --> 00:03:03,000
+a few examples.
+
+44
+00:03:04,000 --> 00:03:09,000
+The first and probably the most simple case that I assume all of you have worked with, if you are following,
+
+45
+00:03:09,000 --> 00:03:11,000
+is, of course, is the bargain.
+
+46
+00:03:11,000 --> 00:03:18,000
+And thus does the bagasse need to be able to ximen private members on glosses.
+
+47
+00:03:18,000 --> 00:03:25,000
+Desautels also needs to be able to get access, sometimes private masses like you saw in the case with
+
+48
+00:03:25,000 --> 00:03:25,000
+Spohrer.
+
+49
+00:03:26,000 --> 00:03:33,000
+Also, when it controls a sequence of mascot's execution to make sure that Nasus Annotated was before
+
+50
+00:03:33,000 --> 00:03:39,000
+each annotation will be executed, before each test case, for example, or in case we need to initialize
+
+51
+00:03:39,000 --> 00:03:45,000
+fields of an object, was Moncks and we need to do this on the for objects that that map was inject
+
+52
+00:03:45,000 --> 00:03:46,000
+more annotations.
+
+53
+00:03:47,000 --> 00:03:51,000
+A lot of things needed to be controlled by test tools and reflection.
+
+54
+00:03:51,000 --> 00:03:52,000
+API helps on this.
+
+55
+00:03:53,000 --> 00:03:57,000
+The next example of using reflection API is extensibility features.
+
+56
+00:03:58,000 --> 00:04:05,000
+And the application may make use of external user defined classes by creating instances of extensibility
+
+57
+00:04:05,000 --> 00:04:08,000
+objects using zarf fully qualified names.
+
+58
+00:04:09,000 --> 00:04:14,000
+This is also relatively specific case and used Durrance advanced programming.
+
+59
+00:04:14,000 --> 00:04:19,000
+But my goal is to make a pro coder from user and discourse, and I'm not joking.
+
+60
+00:04:20,000 --> 00:04:25,000
+So we are also going to learn how to do this visual development environments.
+
+61
+00:04:25,000 --> 00:04:31,000
+Imagine, though, that allows it to generate programming code or tool is used to perform any other
+
+62
+00:04:31,000 --> 00:04:32,000
+visual development.
+
+63
+00:04:33,000 --> 00:04:38,000
+And there is some digital information that this needed to be processed according to the specific rules.
+
+64
+00:04:38,000 --> 00:04:44,000
+And now imagine that you can work in a visual development environment with the selections that you do
+
+65
+00:04:44,000 --> 00:04:45,000
+inside.
+
+66
+00:04:46,000 --> 00:04:51,000
+The whole development process might benefit from making use of that information available.
+
+67
+00:04:52,000 --> 00:04:57,000
+This will help to make proper selections regarding behavior of some components and interactions between
+
+68
+00:04:57,000 --> 00:04:59,000
+Zao HOVs it.
+
+69
+00:04:59,000 --> 00:05:02,000
+Now you at least understands what swift action is for.
+
+70
+00:05:03,000 --> 00:05:03,000
+Let's start.
+
+71
+00:05:03,000 --> 00:05:10,000
+None of the details, all classes that are related to reflexion mechanism are already present in Jaedicke
+
+72
+00:05:10,000 --> 00:05:12,000
+in Java, LANC reflect package.
+
+73
+00:05:12,000 --> 00:05:18,000
+I encourage you to look through the official documentation after the lesson to make sure you can navigate
+
+74
+00:05:18,000 --> 00:05:20,000
+between different types and just package easily.
+
+75
+00:05:21,000 --> 00:05:25,000
+There are numerous of interfaces and glosses today during the lesson.
+
+76
+00:05:25,000 --> 00:05:27,000
+We're going to review majority of them.
+
+77
+00:05:28,000 --> 00:05:33,000
+And as you already understand, you would need to inkers classes from this package and your Java file.
+
+78
+00:05:34,000 --> 00:05:38,000
+OK, so let me start screen sharing and proceed with code examples.
+
+79
+00:05:38,000 --> 00:05:44,000
+Remember that all code examples from the lesson you can always find in attachments to this lesson?
+
+80
+00:05:44,000 --> 00:05:48,000
+I opened them a class from a reflection package of my learning project.
+
+81
+00:05:48,000 --> 00:05:54,000
+I will run a program to walk you through the console output and each line of code in this example.
+
+82
+00:05:55,000 --> 00:06:01,000
+And the first thing to start here is to understand that after completion, class definitions uploaded
+
+83
+00:06:01,000 --> 00:06:02,000
+into the GBM.
+
+84
+00:06:03,000 --> 00:06:07,000
+And there is an object of type gloss for each type.
+
+85
+00:06:07,000 --> 00:06:12,000
+Zet object contains type definition and API to interact with it.
+
+86
+00:06:13,000 --> 00:06:20,000
+So we can say that the instances of the class class represent classes and interfaces in the running
+
+87
+00:06:20,000 --> 00:06:21,000
+Java application.
+
+88
+00:06:22,000 --> 00:06:28,000
+Basically, it will be fair to mention that the objects of class type may represent all the reference
+
+89
+00:06:28,000 --> 00:06:29,000
+types.
+
+90
+00:06:29,000 --> 00:06:35,000
+XOs includes, but not limited to arrays in annotations, cetera.
+
+91
+00:06:35,000 --> 00:06:41,000
+That's why the first things that we need to do is to get the reference to the class object of the specific
+
+92
+00:06:41,000 --> 00:06:41,000
+type.
+
+93
+00:06:41,000 --> 00:06:47,000
+If you remember lesson about object class, then you should remember that one of the masses is that
+
+94
+00:06:47,000 --> 00:06:50,000
+each object has is Geth class method.
+
+95
+00:06:51,000 --> 00:06:58,000
+So I create an instance of the user class that is our nested closet I created here for the sake of example.
+
+96
+00:06:58,000 --> 00:07:02,000
+And I call get class method an instance of the user object.
+
+97
+00:07:03,000 --> 00:07:09,000
+Now, when I have reference to the class object of user time, we can play with the reflection API.
+
+98
+00:07:09,000 --> 00:07:12,000
+Let me come up with some tasks us to solve.
+
+99
+00:07:12,000 --> 00:07:15,000
+And we will learn different classes as we go.
+
+100
+00:07:15,000 --> 00:07:18,000
+For example, let's get the foo class name.
+
+101
+00:07:19,000 --> 00:07:20,000
+The API is pretty intuitive.
+
+102
+00:07:20,000 --> 00:07:23,000
+So you just need to go get name method.
+
+103
+00:07:23,000 --> 00:07:27,000
+As you can see, full class name is printed to consult.
+
+104
+00:07:28,000 --> 00:07:31,000
+Take into account that the user is in master class.
+
+105
+00:07:31,000 --> 00:07:34,000
+It has the lower sign after the name of the rupt class.
+
+106
+00:07:35,000 --> 00:07:40,000
+This is a common convention in Java for the naming of compiler nested classes.
+
+107
+00:07:40,000 --> 00:07:42,000
+Well, what was this first simple task?
+
+108
+00:07:43,000 --> 00:07:44,000
+Let's jump to the next one.
+
+109
+00:07:45,000 --> 00:07:48,000
+Let's find out names of all fields in user class.
+
+110
+00:07:49,000 --> 00:07:55,000
+Pay attention that I have three non static fields and one static and user class, and they have private
+
+111
+00:07:55,000 --> 00:08:01,000
+access modifier, no getters setters to declare to interact with these fields.
+
+112
+00:08:01,000 --> 00:08:08,000
+Using the reference to the class object, we can get array of all fields, fields as a type that contains
+
+113
+00:08:08,000 --> 00:08:11,000
+information about the field of a single class or interface.
+
+114
+00:08:12,000 --> 00:08:15,000
+It also provides it was dynamic access to it.
+
+115
+00:08:15,000 --> 00:08:23,000
+I invoked had declared fields to get the array of fields in which this mass returns all fields from
+
+116
+00:08:23,000 --> 00:08:23,000
+the class.
+
+117
+00:08:24,000 --> 00:08:32,000
+This includes public protected default or so-called package access and private fields, but excludes
+
+118
+00:08:32,000 --> 00:08:33,000
+inherited fields.
+
+119
+00:08:33,000 --> 00:08:38,000
+The results and other methods of the scope get fields and tensions and get fields.
+
+120
+00:08:38,000 --> 00:08:43,000
+Massart returns on the public fields, and the one where broken was reflection.
+
+121
+00:08:43,000 --> 00:08:46,000
+Often we need to get access to private fields, too.
+
+122
+00:08:47,000 --> 00:08:54,000
+That's why in this particular case, I used another method get declared fields that chance all fields,
+
+123
+00:08:54,000 --> 00:08:56,000
+including private ones.
+
+124
+00:08:57,000 --> 00:09:03,000
+And after that, I create a stream out of this array and apply consumer function to each of the field.
+
+125
+00:09:03,000 --> 00:09:09,000
+If you are not familiar with lambda expressions, functional interface and namely consumer type.
+
+126
+00:09:09,000 --> 00:09:13,000
+Feel free to take my post functional programming for Jamma Ingenius.
+
+127
+00:09:13,000 --> 00:09:16,000
+I explained these topics and details in that course.
+
+128
+00:09:17,000 --> 00:09:20,000
+So as you can see, I it to console names of each field.
+
+129
+00:09:21,000 --> 00:09:24,000
+And this is only one thing that we can do this field.
+
+130
+00:09:24,000 --> 00:09:26,000
+We can do much more than this.
+
+131
+00:09:27,000 --> 00:09:29,000
+Let me also show you other things.
+
+132
+00:09:29,000 --> 00:09:32,000
+For example, you can explore that type of a field.
+
+133
+00:09:33,000 --> 00:09:35,000
+Just code must be a generic type.
+
+134
+00:09:36,000 --> 00:09:42,000
+As you can see, when I printed the return type object to console to string masses has been invoked
+
+135
+00:09:42,000 --> 00:09:44,000
+and we see full gloss name.
+
+136
+00:09:44,000 --> 00:09:46,000
+Also, you can check fields modifiers.
+
+137
+00:09:47,000 --> 00:09:49,000
+Just go get modifiers.
+
+138
+00:09:49,000 --> 00:09:51,000
+Massive, this method to chance.
+
+139
+00:09:51,000 --> 00:09:59,000
+And that basically will tell you nothing if you just watch at number to the this end and understand
+
+140
+00:09:59,000 --> 00:10:03,000
+its meaning when it to use another class from Java language.
+
+141
+00:10:03,000 --> 00:10:11,000
+Package modifier, this clause has different measures that takes in as much argument and returned,
+
+142
+00:10:11,000 --> 00:10:12,000
+true or false.
+
+143
+00:10:12,000 --> 00:10:20,000
+We can check these modify Privert, Estatic, this public is protected, is final and many other things.
+
+144
+00:10:20,000 --> 00:10:27,000
+And an example you can see that I call is private Massart and deposit into value rections from get modified
+
+145
+00:10:27,000 --> 00:10:28,000
+SMAS.
+
+146
+00:10:29,000 --> 00:10:34,000
+Considering that all fields have private modifying my example, I receive two for each field.
+
+147
+00:10:35,000 --> 00:10:41,000
+Does it make sense, by the way, is a similar way you can check modifiers of classes and methods?
+
+148
+00:10:41,000 --> 00:10:48,000
+I will not stop on each particular case, but just remember that it is also possible to check modifiers
+
+149
+00:10:48,000 --> 00:10:52,000
+of all the class elements following this approach, using the class.
+
+150
+00:10:52,000 --> 00:10:56,000
+I can get the package name, just schools, the package name, and that's it.
+
+151
+00:10:57,000 --> 00:10:59,000
+Also, there is a specific type package.
+
+152
+00:11:00,000 --> 00:11:03,000
+You can get the instance of this class by calling massive.
+
+153
+00:11:03,000 --> 00:11:07,000
+Get the package if you need to do some operations was package object.
+
+154
+00:11:07,000 --> 00:11:12,000
+If you want to investigate type Iraqui, you can always get the reference to the class.
+
+155
+00:11:12,000 --> 00:11:16,000
+Object of superclass by column gets super class mass.
+
+156
+00:11:16,000 --> 00:11:20,000
+The superclass for all reference types in Java is object.
+
+157
+00:11:21,000 --> 00:11:25,000
+So I get the reference to the instance of object class.
+
+158
+00:11:25,000 --> 00:11:31,000
+The next things that I'd like to show here is how you can check the interfaces that are implemented
+
+159
+00:11:31,000 --> 00:11:31,000
+in class.
+
+160
+00:11:32,000 --> 00:11:35,000
+I print name of each interface to console.
+
+161
+00:11:35,000 --> 00:11:37,000
+And here you can see poufs.
+
+162
+00:11:37,000 --> 00:11:44,000
+I have implemented serializable anticolonial interface in user Granit tensions in Zakouma Sync about
+
+163
+00:11:44,000 --> 00:11:45,000
+all of this.
+
+164
+00:11:45,000 --> 00:11:49,000
+You can explore a code of your program, you as a program execution.
+
+165
+00:11:50,000 --> 00:11:56,000
+So you don't need a developer to investigate code of each program to create some useful utility classes,
+
+166
+00:11:57,000 --> 00:11:59,000
+because code of each program is different.
+
+167
+00:12:00,000 --> 00:12:06,000
+Instead, you can create a code that investigates the code zero, the execution.
+
+168
+00:12:06,000 --> 00:12:09,000
+And on top of that, you can build the logic you wish.
+
+169
+00:12:10,000 --> 00:12:10,000
+Let's move on.
+
+170
+00:12:11,000 --> 00:12:15,000
+There's also another way to get the reference to the instance of a class.
+
+171
+00:12:15,000 --> 00:12:21,000
+We can learn Java loss into Jamam by its name and get the reference to the class object.
+
+172
+00:12:21,000 --> 00:12:26,000
+This is an important example, and we will do something like this later on in our course.
+
+173
+00:12:27,000 --> 00:12:32,000
+Just use for names static mass and pass the full name of the class I pass.
+
+174
+00:12:32,000 --> 00:12:34,000
+He has a full name of the method.
+
+175
+00:12:34,000 --> 00:12:38,000
+Class will use this way of class instantiation.
+
+176
+00:12:38,000 --> 00:12:41,000
+One, we actually don't need the object of this type.
+
+177
+00:12:41,000 --> 00:12:45,000
+All we can is created and called get class method.
+
+178
+00:12:45,000 --> 00:12:48,000
+That's why we can load the class by its name.
+
+179
+00:12:49,000 --> 00:12:51,000
+Pay attention to this method.
+
+180
+00:12:51,000 --> 00:12:54,000
+Invocation maestro class not found exception.
+
+181
+00:12:54,000 --> 00:12:56,000
+This may happen in case you pass.
+
+182
+00:12:56,000 --> 00:12:59,000
+Last names are just absent in the class boss.
+
+183
+00:13:00,000 --> 00:13:02,000
+Also, we can get constructors.
+
+184
+00:13:02,000 --> 00:13:06,000
+Constructor is a separate type from General Lenca effect package.
+
+185
+00:13:06,000 --> 00:13:09,000
+Heavens, reference is a constructor object.
+
+186
+00:13:09,000 --> 00:13:11,000
+We can do really a lot of sync's, was it?
+
+187
+00:13:12,000 --> 00:13:17,000
+But for the sake of this example, only will prints number of constructors and their names.
+
+188
+00:13:18,000 --> 00:13:21,000
+In this example, I will get declared constructor.
+
+189
+00:13:21,000 --> 00:13:30,000
+SMAS is the name important is the same as in the masses, yet declared constructor means return of all
+
+190
+00:13:30,000 --> 00:13:31,000
+constructors.
+
+191
+00:13:31,000 --> 00:13:35,000
+Is that somebody Covid in the class, including private ones?
+
+192
+00:13:35,000 --> 00:13:42,000
+There is another massive get constructors that Massata returns on the public constructors.
+
+193
+00:13:42,000 --> 00:13:45,000
+There are also masses to the specific constructor.
+
+194
+00:13:45,000 --> 00:13:51,000
+Get declared constructor and git constructor with class variable lengths argument.
+
+195
+00:13:51,000 --> 00:13:58,000
+You can get the references, specific constructors that you need using the types of constructor parameters.
+
+196
+00:13:59,000 --> 00:14:04,000
+For example, here I want to get the reference to the private constructor parameter of type string.
+
+197
+00:14:04,000 --> 00:14:08,000
+I'm just possessory Gloucester's and Massett invocation.
+
+198
+00:14:08,000 --> 00:14:14,000
+This massive miswrote two exceptions is the first one is no such massive exception.
+
+199
+00:14:15,000 --> 00:14:20,000
+This exceptionable strong JS constructor was a specified parameter types and wasn't found.
+
+200
+00:14:20,000 --> 00:14:24,000
+And the second exceptions may be strong is a security exception.
+
+201
+00:14:24,000 --> 00:14:29,000
+This exception might be sold by the security manager to indicate a security violation.
+
+202
+00:14:30,000 --> 00:14:36,000
+As you can see in console, we have managed to get the reference to a private constructor, the similar
+
+203
+00:14:36,000 --> 00:14:37,000
+way we can work with masses.
+
+204
+00:14:38,000 --> 00:14:45,000
+We get all masses, including privates, once we can get on the public masses and we can get specific
+
+205
+00:14:45,000 --> 00:14:45,000
+masses.
+
+206
+00:14:46,000 --> 00:14:47,000
+Let me show you a few examples here.
+
+207
+00:14:48,000 --> 00:14:53,000
+I cogat declare mass it's massive and print massive names to console.
+
+208
+00:14:53,000 --> 00:15:00,000
+In the next example here, I'm getting massive by its name and by list of these arguments.
+
+209
+00:15:00,000 --> 00:15:03,000
+This is how we can separate overload.
+
+210
+00:15:03,000 --> 00:15:04,000
+That's massive.
+
+211
+00:15:05,000 --> 00:15:08,000
+The first message argument is a method name, just ring value.
+
+212
+00:15:09,000 --> 00:15:12,000
+And after that, those verbal length's arguments of that class.
+
+213
+00:15:13,000 --> 00:15:16,000
+I want to get the message that takes user argument.
+
+214
+00:15:16,000 --> 00:15:21,000
+That's why I passed pass user class here and the printers and Massett to consult.
+
+215
+00:15:22,000 --> 00:15:28,000
+As you can see, we have managed to get the object of representation of this massive to perform any
+
+216
+00:15:28,000 --> 00:15:29,000
+actions we need.
+
+217
+00:15:29,000 --> 00:15:31,000
+Was it when we tried to get.
+
+218
+00:15:32,000 --> 00:15:37,000
+Always remember that we can face was no such massive exception and security exception.
+
+219
+00:15:38,000 --> 00:15:44,000
+These are checked exceptions, and I will recommend you to handle those exceptions for the sake of the
+
+220
+00:15:44,000 --> 00:15:45,000
+demo.
+
+221
+00:15:45,000 --> 00:15:49,000
+I put them next Ostrowsky in my main message.
+
+222
+00:15:49,000 --> 00:15:50,000
+OK.
+
+223
+00:15:50,000 --> 00:15:52,000
+They learned the API and the high level.
+
+224
+00:15:53,000 --> 00:15:58,000
+Now you know how you can get the reference to the definition of type elements, such as fields, constructors,
+
+225
+00:15:58,000 --> 00:16:03,000
+methods, interface, a simple amount of superclass, et cetera.
+
+226
+00:16:03,000 --> 00:16:09,000
+Now let's understand this topic and understand how to work with object of these types.
+
+227
+00:16:09,000 --> 00:16:14,000
+Namely, I want you to understand what we can do with them.
+
+228
+00:16:14,000 --> 00:16:16,000
+Let me start from the constructor.
+
+229
+00:16:17,000 --> 00:16:22,000
+I am going to show you what important operations we may perform with objects of this type.
+
+230
+00:16:22,000 --> 00:16:25,000
+I get the reference to the default constructor.
+
+231
+00:16:25,000 --> 00:16:32,000
+And also I am going to use the reference to a constructor with parameter that we got in previous examples.
+
+232
+00:16:32,000 --> 00:16:34,000
+Hence the reference to the constructor.
+
+233
+00:16:35,000 --> 00:16:41,000
+We can create an instance of this class by calling new instance method, and in case we need to pass
+
+234
+00:16:41,000 --> 00:16:44,000
+some arguments to instantiate the object of this type.
+
+235
+00:16:44,000 --> 00:16:46,000
+We just passed them and that's it.
+
+236
+00:16:47,000 --> 00:16:54,000
+I print these user objects to consult that tensions that I have managed even to instantiate object based
+
+237
+00:16:54,000 --> 00:16:56,000
+on the private constructor.
+
+238
+00:16:56,000 --> 00:17:03,000
+I have just another email and the email field was initialized in user object was valued even by me.
+
+239
+00:17:04,000 --> 00:17:05,000
+Isn't that cool?
+
+240
+00:17:05,000 --> 00:17:08,000
+Do you feel the power of reflection already or not yet?
+
+241
+00:17:09,000 --> 00:17:11,000
+Let me show you another trick was a few.
+
+242
+00:17:11,000 --> 00:17:15,000
+All our fields declared in user gloss are private.
+
+243
+00:17:15,000 --> 00:17:18,000
+And this makes this trick even more interesting.
+
+244
+00:17:18,000 --> 00:17:24,000
+Different frameworks may insert those in the field, even if there are no public systems.
+
+245
+00:17:24,000 --> 00:17:26,000
+For example, Mosquita framework.
+
+246
+00:17:27,000 --> 00:17:31,000
+When they use annotation inject, most fields of compatable was marked.
+
+247
+00:17:31,000 --> 00:17:36,000
+Darbs are populated with mock objects or in spring framework.
+
+248
+00:17:36,000 --> 00:17:42,000
+When I configure my spring events, I described object of what types I needed to be injected.
+
+249
+00:17:42,000 --> 00:17:45,000
+Now I'm going to show you how to do that.
+
+250
+00:17:46,000 --> 00:17:51,000
+For example, let's give the reference to the first name field and initialize it.
+
+251
+00:17:51,000 --> 00:17:55,000
+You already know that I need to use get declared fields Massud.
+
+252
+00:17:55,000 --> 00:18:01,000
+I can extract fields that they need by its name in addition to all previous exceptions.
+
+253
+00:18:01,000 --> 00:18:04,000
+This massive, nice rule, no such field exception.
+
+254
+00:18:05,000 --> 00:18:10,000
+I believe that from exception name, you can understand when this exception will be thrown.
+
+255
+00:18:11,000 --> 00:18:15,000
+The first things that we need to do now is to set accessable mode.
+
+256
+00:18:15,000 --> 00:18:18,000
+This is needed for private entities inside the class.
+
+257
+00:18:19,000 --> 00:18:25,000
+Oh, with the exception, Joon's interaction with this entity I call set accessible to.
+
+258
+00:18:25,000 --> 00:18:30,000
+After this, I can set the value to the field without any fear of exception.
+
+259
+00:18:31,000 --> 00:18:35,000
+The whole region knows that field is a property of some object.
+
+260
+00:18:35,000 --> 00:18:37,000
+Xus to initialize the field.
+
+261
+00:18:38,000 --> 00:18:42,000
+We need to specify the object where we want to initialize this field.
+
+262
+00:18:43,000 --> 00:18:43,000
+Does it make sense?
+
+263
+00:18:44,000 --> 00:18:48,000
+Massart set of the field takes two massive arguments.
+
+264
+00:18:48,000 --> 00:18:52,000
+The first one is the object that is used to initialize field.
+
+265
+00:18:52,000 --> 00:18:55,000
+And the second one is a values that will be inserted.
+
+266
+00:18:55,000 --> 00:18:58,000
+Those that fields one that brings the object to console.
+
+267
+00:18:58,000 --> 00:19:04,000
+You can notice that first name field was updated with the values that we have just sent.
+
+268
+00:19:05,000 --> 00:19:11,000
+One more thing thread here is that for certain primitives, types exist, separate masses like set in,
+
+269
+00:19:12,000 --> 00:19:19,000
+said double seven, boolean, etc. For all reference types, you can use set methods that takes object
+
+270
+00:19:19,000 --> 00:19:23,000
+s first methods, arguments, what to do in case there is a static field.
+
+271
+00:19:23,000 --> 00:19:26,000
+Everson's is the same beside Wansink.
+
+272
+00:19:26,000 --> 00:19:30,000
+You don't need to parse the reference to an object in this case.
+
+273
+00:19:30,000 --> 00:19:36,000
+Just personal instead, like I do in this example, you can see that static.
+
+274
+00:19:36,000 --> 00:19:38,000
+This has another value.
+
+275
+00:19:38,000 --> 00:19:43,000
+Now we learned how to set field values, but how to read fields values.
+
+276
+00:19:43,000 --> 00:19:44,000
+Very simple.
+
+277
+00:19:45,000 --> 00:19:46,000
+You need to use gets Massart.
+
+278
+00:19:47,000 --> 00:19:48,000
+The algorithm is the same.
+
+279
+00:19:49,000 --> 00:19:51,000
+You get the reference to fields first.
+
+280
+00:19:51,000 --> 00:19:52,000
+We already did that.
+
+281
+00:19:53,000 --> 00:20:00,000
+So I would just use first name field and I'd field after that to change access mode in case fields are
+
+282
+00:20:00,000 --> 00:20:01,000
+private.
+
+283
+00:20:01,000 --> 00:20:03,000
+We have a really cool set.
+
+284
+00:20:03,000 --> 00:20:05,000
+Sesame masses for both fields.
+
+285
+00:20:05,000 --> 00:20:07,000
+That's why I don't do it again.
+
+286
+00:20:08,000 --> 00:20:10,000
+And after that, I just get massive.
+
+287
+00:20:11,000 --> 00:20:17,000
+I need to pass reference to the object where I want to read field in this field to study.
+
+288
+00:20:17,000 --> 00:20:19,000
+You shouldn't pass that object.
+
+289
+00:20:20,000 --> 00:20:22,000
+Is this clear in console?
+
+290
+00:20:22,000 --> 00:20:25,000
+You can see how I managed to extract the first name.
+
+291
+00:20:25,000 --> 00:20:31,000
+And I leave this for primitive tribes, use a separate group of masses like get in together, boolean,
+
+292
+00:20:31,000 --> 00:20:35,000
+etc. to get the value of reference types.
+
+293
+00:20:35,000 --> 00:20:38,000
+You can go just get massive, right in our example.
+
+294
+00:20:39,000 --> 00:20:42,000
+Let me show you how we can work with masses.
+
+295
+00:20:42,000 --> 00:20:45,000
+We can involve them on the object when we need.
+
+296
+00:20:46,000 --> 00:20:50,000
+Basically, we have two masses that can help us to get the reference to the object.
+
+297
+00:20:50,000 --> 00:20:54,000
+Masses get declared method and get massive.
+
+298
+00:20:55,000 --> 00:21:01,000
+If I want to get a reference to the private mass, I have to use get declared mass in all cases.
+
+299
+00:21:01,000 --> 00:21:06,000
+And it was the strings that contains massive name that I would like to get.
+
+300
+00:21:06,000 --> 00:21:10,000
+And additionally, we need to pass colossus of parameter such.
+
+301
+00:21:11,000 --> 00:21:13,000
+This is very blancs argument.
+
+302
+00:21:13,000 --> 00:21:18,000
+So basically you can posse's and nothing here or colossus of all arguments.
+
+303
+00:21:19,000 --> 00:21:26,000
+I plus private method name and sue here because this massive base string how I can find this urines
+
+304
+00:21:26,000 --> 00:21:33,000
+around that again, just those examples of how you can get information about all masses in class after
+
+305
+00:21:33,000 --> 00:21:38,000
+having the references to all masses, you can expose any names and parameters.
+
+306
+00:21:38,000 --> 00:21:42,000
+That's how you can build code that explores the program.
+
+307
+00:21:42,000 --> 00:21:43,000
+Jawanza runtime.
+
+308
+00:21:44,000 --> 00:21:49,000
+After I have reference to this method, I have to call set accessible to true.
+
+309
+00:21:50,000 --> 00:21:56,000
+Since this is private mass, I need to perform this massive communication with Iran as a program execution.
+
+310
+00:21:57,000 --> 00:21:59,000
+After that, I can invoke Massett.
+
+311
+00:22:00,000 --> 00:22:02,000
+And again, similarities and no static fields.
+
+312
+00:22:02,000 --> 00:22:07,000
+I need an object doing the rows and massive all because massive.
+
+313
+00:22:07,000 --> 00:22:09,000
+It is a behavior of an object.
+
+314
+00:22:09,000 --> 00:22:13,000
+So once I get the mass, I can invoke the Private Massett on an object.
+
+315
+00:22:14,000 --> 00:22:18,000
+And you can see that I postering argument do in console.
+
+316
+00:22:18,000 --> 00:22:20,000
+You might notice a private mass has been called.
+
+317
+00:22:21,000 --> 00:22:22,000
+How do you like it?
+
+318
+00:22:23,000 --> 00:22:26,000
+As you can see, there are no more orders for reflection.
+
+319
+00:22:26,000 --> 00:22:30,000
+API and encapsulation means nothing for reflection.
+
+320
+00:22:30,000 --> 00:22:37,000
+By the way, this is also one of the reasons not to use the reflection API, because it may violate
+
+321
+00:22:37,000 --> 00:22:37,000
+encapsulation.
+
+322
+00:22:38,000 --> 00:22:44,000
+Reflection that you may access fields and perform operations that you are not supposed to perform.
+
+323
+00:22:44,000 --> 00:22:48,000
+But as we discussed Zimride, the case is one reflection.
+
+324
+00:22:48,000 --> 00:22:54,000
+API is needed to perform some actions that will make the development process easier.
+
+325
+00:22:54,000 --> 00:22:56,000
+For example, was aesthetic Massart.
+
+326
+00:22:56,000 --> 00:22:59,000
+Everson is the same beside one sink.
+
+327
+00:22:59,000 --> 00:23:03,000
+You shouldn't parse the reference to an object to static muscle.
+
+328
+00:23:04,000 --> 00:23:06,000
+Here's an example of static mess recreation.
+
+329
+00:23:07,000 --> 00:23:09,000
+As you can see, there is nothing special.
+
+330
+00:23:10,000 --> 00:23:12,000
+That's all what I wanted to share with you today.
+
+331
+00:23:13,000 --> 00:23:15,000
+Let's review what we have learned in this lesson.
+
+332
+00:23:16,000 --> 00:23:21,000
+In this lesson we learned was a reflection API is and why we need it.
+
+333
+00:23:21,000 --> 00:23:28,000
+We reviewed that reflect package, and after that we started our reflection API on examples.
+
+334
+00:23:29,000 --> 00:23:36,000
+You saw how we can work with different closs entities such as fields, constructors, methods, interfaces,
+
+335
+00:23:36,000 --> 00:23:39,000
+super classes with the help of a section API.
+
+336
+00:23:40,000 --> 00:23:45,000
+Separate group of examples related was private class entities and how to work with them.
+
+337
+00:23:45,000 --> 00:23:48,000
+Private constructors, private masses, sprout's fields.
+
+338
+00:23:49,000 --> 00:23:52,000
+That's all what I plan to share with you today.
+
+339
+00:23:52,000 --> 00:23:53,000
+Thanks a lot for your attention.
+
+340
+00:23:54,000 --> 00:23:56,000
+Have a great day and see you in the next lesson.
+