background top icon
background center wave icon
background filled rhombus icon
background two lines icon
background stroke rhombus icon

Download "Урок по Java 68: Многопоточность 3: Синхронизация"

input logo icon
Video tags
|

Video tags

java
multithreading
synchronize
синхронизация
многопоточность
видео уроки
урок
lesson
free
бесплатные
программирование на Java
Java development
Java программирование
Java (programming Language)
туториал по Java
java tutorial
курсы Java
Java для чайников
обучение java
изучение java
Subtitles
|

Subtitles

subtitles menu arrow
  • ruRussian
Download
00:00:02
main problems in multi-threaded
00:00:05
java applications
00:00:06
related to precision and how to
00:00:11
solve the problem using synchronization.
00:00:13
Look, imagine we have a
00:00:16
class May rules which is an extender, so you
00:00:29
and I have already studied how to create
00:00:31
here we will reward method of wounds and here we
00:00:41
will write something now, yes here we
00:00:45
will have several threads my said
00:00:49
fred
00:00:51
and exactly the same second thread the problem
00:00:57
in terms of accuracy is that this is how we will
00:01:03
start it all start multithreading
00:01:09
the problem is that sometimes
00:01:11
we have hit resources that, well, let's
00:01:14
say
00:01:19
resources that
00:01:25
can use several threads
00:01:27
at the same time, that is, imagine two
00:01:28
threads at the same time trying to access some
00:01:31
resources with a file or a network,
00:01:34
write something there, and in general,
00:01:37
sometimes we can have problems, that is,
00:01:39
the standard one is usually an example with an account on
00:01:44
which there is money, that is, two
00:01:46
threads can access it and
00:01:48
somehow get to write off money from it,
00:01:51
and so on, in general, let’s
00:01:53
abstract from all accounts, we will
00:01:55
imagine we have some kind of
00:01:58
resource class, it has a variable and to
00:02:04
which we will gain access and
00:02:06
some kind of public two method we have
00:02:12
that will fix
00:02:13
the food that will change it change
00:02:17
how it will simply increase the area
00:02:20
exactly by one, that is, we take int and
00:02:23
equals here and then we will have and + + and
00:02:29
then we with and equal
00:02:32
and climb everything would be simple, yes, that is, we
00:02:35
simply increase one and by one
00:02:38
now we can our environment we want to work with it,
00:02:42
we want to take
00:02:45
some resource here for a set of these and let’s say
00:02:52
light per resource we do
00:02:55
here we can hand over to create a sauce,
00:03:06
let's although yes we have some kind of
00:03:10
resource in this resource, we and our hands will
00:03:14
say the amount is 5, let it be up to what next
00:03:18
next we this resource in our rap, that
00:03:21
is, we make one resource from red 2,
00:03:28
we do the same thing as we do should
00:03:32
happen in our program, well, let's
00:03:34
also drive these sites, make mais red 2
00:03:51
and then we take we see our resource
00:03:56
before the resource and what does it mean what happens in what
00:04:02
program we create a resource object,
00:04:04
set the head of the traffic police, then
00:04:07
let's say the values ​​are 5, then we create two from the ride, two threads in
00:04:11
we put this resource in them, that is, we have it
00:04:13
here, this will be our
00:04:15
internal resource and then we launch and that’s
00:04:20
all we all we need to do is
00:04:23
in these threads increase the value of our
00:04:25
resource by one here, let’s say like this, we’ll
00:04:29
write it like this,
00:04:30
we’ll take the resource and than and
00:04:34
that is, we have two threads, both of them
00:04:37
will launch this ran method
00:04:39
when we press start and this run method
00:04:42
will go to the than method and increase it by
00:04:45
one, that is, we have this one
00:04:47
and will run twice, the first time we
00:04:49
will increase by one the second time we
00:04:52
let's increase by one more, we also wo
00:04:54
n't have 5 7 then here when we get it out we
00:04:56
will have a seven, it seems everything is very
00:04:59
simple, yes, that is, here we are for johnny,
00:05:01
we said let's wait until it's all over
00:05:03
and then we'll see what
00:05:08
assignment we run about seven times seven
00:05:15
and then yes, that is, we will most likely
00:05:17
have 7, but in fact everything is not so
00:05:19
simple, in fact the point is that there are
00:05:22
several threads waiting for us and they may make
00:05:26
a little mistake, see how everything can happen
00:05:29
here somewhere
00:05:31
the code can stop and do so to speak, I have a
00:05:35
variable and but let's say, let's say this goes
00:05:38
from 1,
00:05:43
he comes here and writes int and equals
00:05:46
here and yes, that is, he wrote it down at this
00:05:50
moment and we have equals like this, but then
00:05:56
our flow breaks off, she comes here for the
00:05:58
second term and he does the same thing, he
00:06:01
writes and i is equal to here and and
00:06:07
medium let's write 2 for him and it
00:06:13
will be equal to the same peaks and now we
00:06:16
increase
00:06:18
i + + that is, with red 2 and is already equal to 6
00:06:29
somehow and now we just with
00:06:33
and equals and a and we have equals 6 until
00:06:39
everything starts up like a layer but now
00:06:41
we return to Wednesday one from Wednesday
00:06:45
one we have and the same and we already have equals 5
00:06:52
and we write and it will give a plus at this moment
00:06:56
we have 1 environment and will be equal to 6 and we take
00:07:00
write here and equal to
00:07:03
and and thus we have and will be equal to 6
00:07:08
that is, we basically have the
00:07:10
possibility that at this moment here is
00:07:12
when we will delete at this
00:07:15
moment we have the termination of the
00:07:17
first thread will terminate and the execution of the second will begin
00:07:20
and then we can have a print to then
00:07:23
we can output here not 76,
00:07:28
of course we can run it many times,
00:07:30
nothing is guaranteed, this is very bad, we
00:07:33
cannot control this process, you
00:07:35
see 6 it was output, yes it was the case 7 types of
00:07:39
you power 6 finally, here I usually do it
00:07:42
in order to demonstrate so
00:07:44
that the probability is an order of magnitude greater,
00:07:46
look, I have such a trick, I
00:07:50
take it, I can do it this way, I take it
00:07:52
Wednesday oh my light my neighbor name for you
00:08:01
here I can write it like this
00:08:09
he shits them get names on
00:08:15
then I'll do such a funny thing I'll
00:08:22
write
00:08:24
Fred ate what happens when I click
00:08:28
when I click ate here the
00:08:31
execution of this thread stops and this thread
00:08:33
returns to the pool then java begins to
00:08:38
select from the pins some next
00:08:40
thread it can choose how this one is like the
00:08:42
first thread, then some other one, that
00:08:44
is, we have a probability there, roughly speaking,
00:08:46
fifty-fifty that we will have 1 or
00:08:48
2 executed, so when we run
00:08:50
this program multidimensionally, you see
00:08:59
76,667, that is, we have like a blast furnace ram
00:09:01
more or less values ​​will be obtained,
00:09:04
and this is a very big problem for us
00:09:07
because several threads do not work
00:09:08
with the resource, that is, imagine that this is a
00:09:10
cash account
00:09:11
and money is debited on this cheek, that
00:09:15
is, you have 100 dollars lying there and then
00:09:18
some left-handed programmer writes with a crooked hand
00:09:19
Here’s the code that just
00:09:22
starts writing off something there or
00:09:24
adding until you came, you got it twice, your
00:09:27
salary came, for example,
00:09:29
they threw in 100 dollars, but the first time
00:09:32
the dollar increased, the second time there was no sign up and
00:09:35
you have a place of 200 dollars left, 100
00:09:37
will you be offended of course they will be
00:09:39
therefore how such problems are solved
00:09:41
such a problem is solved very simply with the
00:09:43
help of synchronization you won’t believe
00:09:46
how simple it is all we need to
00:09:48
do is write the
00:09:50
keyword sims here we have that’s all the problem is
00:09:55
solved now we will have it all the time all the
00:09:59
time it will be 7 how much no matter how many times
00:10:01
we run it,
00:10:02
we will have 777 I can run 50 at least a hundred times,
00:10:10
yes it will be
00:10:11
why synchronization is such a cool
00:10:15
thing that how can I explain this to you, it
00:10:19
says that I have a
00:10:22
method here that is being executed, it must
00:10:24
be synchronized, that is, it
00:10:27
must not be interrupted and somewhere here
00:10:29
inside if I suddenly cut off all the food I will
00:10:34
leave with a rand floor
00:10:37
but in the pool of threads and no other thread
00:10:40
will be able to come here that is, if it is
00:10:42
somewhere here in the middle there on the thirty-
00:10:44
eighth line it is cut off now
00:10:47
it comes to us 2 Harry's flow of sushi I
00:10:49
want to perform an
00:10:50
outfit for him no, this method is not
00:10:53
synchronized until the previous flow
00:10:56
reaches the very end, then you
00:10:58
will not be able to
00:10:59
execute it, it works using log off,
00:11:02
that is, we have each class with
00:11:04
such an invisible varnish and
00:11:06
well, imagine this is not some kind of analogue
00:11:09
let’s say a key, you come to
00:11:11
work on a bicycle and
00:11:14
many more programmers come to your work, you
00:11:16
have one key to the shower, you go and take it and
00:11:21
wash yourself and maybe get out of the shower there,
00:11:24
go, I don’t know, drink coffee, then
00:11:28
go back to the shower, let’s say with oil
00:11:30
that -what do you need or you forgot something, a
00:11:32
towel, go to work,
00:11:34
come back, but the essence remains the same, that
00:11:36
this key is like a log while he is
00:11:40
no other programmer or an
00:11:41
employee who arrives on a
00:11:43
bicycle wants to take a shower, he
00:11:45
will not be able to take a shower until you release it,
00:11:48
put the key in its place, it will
00:11:50
stand and wait, that is, we will have
00:11:52
a queue there, perhaps, and so on, but
00:11:54
nevertheless, that is, in this way, we
00:11:56
can block threads and wait until
00:11:59
this log is free, also
00:12:02
called
00:12:03
monitor, in fact,
00:12:04
there is a certain difference between lessons and monitors, but
00:12:07
some, as it were, in many literature
00:12:11
and many programmers call them, do not
00:12:14
distinguish them much because there the difference is not
00:12:18
particularly fundamental, just a monitor, well,
00:12:20
as if it could have this broader concept of a
00:12:24
monitor, and so it would be like this
00:12:28
could it be on the object or something, that is, which
00:12:30
sits directly behind the object
00:12:32
on the general if you come across somewhere such a
00:12:35
name as a monitor, keep in mind that
00:12:37
this is such a varnish on the object, then
00:12:41
what else can I say about this,
00:12:47
usually everything is synchronized, but you want the
00:12:50
object itself let’s
00:12:52
say we can synchronize,
00:12:54
that is, not just a method, we can make
00:12:57
some kind of pieces of code, that is, we
00:13:00
can have a synchronized blog,
00:13:01
that is, we can write something else like this
00:13:04
synchronously is diss boyz
00:13:08
and all this will be placed in some kind of block
00:13:14
absolutely the same thing, there is no difference,
00:13:16
that is, when Sir Knight happens to us,
00:13:19
it happens to us on some object,
00:13:22
for example, if we had two
00:13:25
completely different source objects here, we
00:13:28
counted 1 here and another here, then
00:13:31
we would have problems different problems
00:13:33
different objects the problem is that we
00:13:35
use the same object in our streams,
00:13:38
we have to synchronize this object,
00:13:42
not even synchronize the vase,
00:13:45
we generally
00:13:51
usually make all fields private, but
00:13:54
here we don’t necessarily have to
00:13:57
do there, let's say
00:13:58
guitar for food, there is
00:14:04
no target here, something like this, it all should
00:14:21
be in the right way,
00:14:25
that is, in good terms, all fields
00:14:28
are made private and all methods that
00:14:32
work
00:14:34
with this or changing
00:14:37
the value, they should all be
00:14:39
synchronized, that is, in good terms according to our
00:14:41
account, we have some kind of code that
00:14:43
should have all the methods that have my
00:14:46
values ​​​​should be synchronized,
00:14:48
but not necessarily all the methods should be,
00:14:51
that is, let’s say Gleb and I can leave it
00:14:53
here, it just returns some
00:14:55
value
00:14:56
that we get at a certain point in
00:14:59
time when it’s there maybe 4
00:15:02
once 5 like once 6 yes there
00:15:05
here especially I know that we have objects
00:15:08
for John and I will have the final
00:15:10
value so I
00:15:11
don’t need to synchronize here, but in
00:15:15
fact there is no need for a set here
00:15:18
but during the day, just to
00:15:20
demonstrate that several
00:15:23
objects, not several methods, can be
00:15:26
synchronized, and
00:15:28
they synchronize on an object, that is,
00:15:30
they will improve the object, there would be several
00:15:32
objects, there would be several varnishes, but on
00:15:34
each one, that’s
00:15:36
actually if, as I already
00:15:40
said, if here there was one object
00:15:42
here and another, we thought that two threads
00:15:45
were working with different objects, the problem
00:15:48
would not arise at all, each of them
00:15:49
would increase its object by one,
00:15:52
the problem is that there is one resource, as I have already
00:15:55
repeated, resource one value here is
00:15:58
one for him in two threads, but we
00:16:01
took here in this way for
00:16:06
synchronized we said for
00:16:07
synchronizing this thread, you could,
00:16:10
of course, create some kind of main
00:16:13
there on it to synchronize the date, but sometimes
00:16:16
you may need to synchronize objects on some
00:16:17
other object
00:16:19
directly here we have the
00:16:21
need to synchronize
00:16:22
exclusively on this object, well,
00:16:28
something like this, that is, what you should and show
00:16:31
let’s repeat what we should take away from
00:16:33
this object and from this lesson
00:16:36
is that we have several threads that can
00:16:39
work with one object and when they
00:16:41
change, it is advisable for us to put everything in
00:16:45
something like this changes that can be
00:16:49
interrupted, let's allow the middle of one of
00:16:52
the threads to transfer control to another and
00:16:54
we know that we have some kind of
00:16:56
problems here with the concurrency of threads,
00:17:00
we can have all these methods
00:17:02
that change the value of internal
00:17:04
states, it is best to interfere with the
00:17:07
synchronized
00:17:08
method, that is, place using its
00:17:10
synchronicity method, we can also
00:17:15
optionally mark the son format with the son format method,
00:17:17
we can place a synchronized
00:17:19
block, that is, if we have a
00:17:21
south pressure chamber here
00:17:24
and, for example, it was introduced and
00:17:27
this did not affect our code in any way,
00:17:30
then we can code
00:17:32
exclusively some kind What does
00:17:35
synchronization mean? This means that until one
00:17:38
of the threads reaches the end, no
00:17:40
other thread will be able to execute this
00:17:43
code. As you can see, everything is very simple,
00:17:45
multithreading is nothing complicated, this is
00:17:48
the main problem of multithreading, access
00:17:51
to common resources, it will be more
00:17:55
interesting later, we will also protect
00:17:58
multithreading there will be interesting topics for
00:18:00
today everyone, subscribe and
00:18:03
like everyone bye

Description:

Cкидки до 22-го января на все курсы всего за 9.99: Каждый купон расчитан на 10 покупок, спешите! Новый курс по Photoshop: https://www.udemy.com/course/draft/3356128/?couponCode=4CD42A416E75E5BB51B2 HIBERNATE: https://www.udemy.com/course/hibernate-kurs/?couponCode=A0CA88708A2DA6C96137 JPA: https://www.udemy.com/course/jpa-kurs/?couponCode=FF4582C15F37936F4D5A HTML + CSS: https://www.udemy.com/course/html-kurs/?couponCode=E616CB401A8D6C38DB4E MAVEN: https://www.udemy.com/course/maven-kurs/?couponCode=7A9538F9B3BD31257157 GIT: https://www.udemy.com/course/git-study/?couponCode=A6017C034D6EC07ACC33 KOTLIN https://www.udemy.com/course/kotlin-best-course/?couponCode=125C8D6713F57D762681 SQL: https://www.udemy.com/course/sql-kurs/?couponCode=7888161B79F724F8A3F1 IDEA https://www.udemy.com/course/intellij-idea/?couponCode=4B28773B32B3CDA9DA20 Паттерны Java: https://www.udemy.com/course/java-patterns/?couponCode=F369DA5D686AA2DB4DE3 Java EE: https://www.udemy.com/course/kurs-java-ee/?couponCode=CB9E8C3E379038EEBBB0 Английский язык: https://www.udemy.com/course/eng-course/?couponCode=786CC96F3EB694A18F7C JAVA: https://www.udemy.com/course/java-best/?couponCode=6AAD5A31E48C6ECEAC9D Apache Spark: https://www.udemy.com/course/apache-spark-course/?couponCode=9AB448B8ACDFDFCC9746

Preparing download options

popular icon
Popular
hd icon
HD video
audio icon
Only sound
total icon
All
* — If the video is playing in a new tab, go to it, then right-click on the video and select "Save video as..."
** — Link intended for online playback in specialized players

Questions about downloading video

mobile menu iconHow can I download "Урок по Java 68: Многопоточность 3: Синхронизация" video?mobile menu icon

  • http://unidownloader.com/ website is the best way to download a video or a separate audio track if you want to do without installing programs and extensions.

  • The UDL Helper extension is a convenient button that is seamlessly integrated into YouTube, Instagram and OK.ru sites for fast content download.

  • UDL Client program (for Windows) is the most powerful solution that supports more than 900 websites, social networks and video hosting sites, as well as any video quality that is available in the source.

  • UDL Lite is a really convenient way to access a website from your mobile device. With its help, you can easily download videos directly to your smartphone.

mobile menu iconWhich format of "Урок по Java 68: Многопоточность 3: Синхронизация" video should I choose?mobile menu icon

  • The best quality formats are FullHD (1080p), 2K (1440p), 4K (2160p) and 8K (4320p). The higher the resolution of your screen, the higher the video quality should be. However, there are other factors to consider: download speed, amount of free space, and device performance during playback.

mobile menu iconWhy does my computer freeze when loading a "Урок по Java 68: Многопоточность 3: Синхронизация" video?mobile menu icon

  • The browser/computer should not freeze completely! If this happens, please report it with a link to the video. Sometimes videos cannot be downloaded directly in a suitable format, so we have added the ability to convert the file to the desired format. In some cases, this process may actively use computer resources.

mobile menu iconHow can I download "Урок по Java 68: Многопоточность 3: Синхронизация" video to my phone?mobile menu icon

  • You can download a video to your smartphone using the website or the PWA application UDL Lite. It is also possible to send a download link via QR code using the UDL Helper extension.

mobile menu iconHow can I download an audio track (music) to MP3 "Урок по Java 68: Многопоточность 3: Синхронизация"?mobile menu icon

  • The most convenient way is to use the UDL Client program, which supports converting video to MP3 format. In some cases, MP3 can also be downloaded through the UDL Helper extension.

mobile menu iconHow can I save a frame from a video "Урок по Java 68: Многопоточность 3: Синхронизация"?mobile menu icon

  • This feature is available in the UDL Helper extension. Make sure that "Show the video snapshot button" is checked in the settings. A camera icon should appear in the lower right corner of the player to the left of the "Settings" icon. When you click on it, the current frame from the video will be saved to your computer in JPEG format.

mobile menu iconWhat's the price of all this stuff?mobile menu icon

  • It costs nothing. Our services are absolutely free for all users. There are no PRO subscriptions, no restrictions on the number or maximum length of downloaded videos.