Hello, yes, students today will start learning a new topic, Moonface Riden, this is huge topic,
and after this course, you will have a lot of knowledge that you can apply in different programming
languages to support not just execution, but in scope of this course.
I will show you how MultiThreaded works on Java examples and take into account this is the first lesson
of new topic, this lesson a little bit more theoretical one to be sure that we have enough high level
knowledge and understanding before we'll start sharing, quote, examples in the next lesson.
That's why today we'll focus our attention on such questions as what is the process in our computers?
What is the threat of execution?
What is multithreaded in programming also in this lesson and explain how multiscreen works and what
threats and translation means.
And the standard answers on these questions will bring us to the point where we can discuss with you
why multiscreen is needed and what a benefit, something which is written.
And also we'll discuss dark side of multithreaded to understand it, drawbacks and what we should always
take into account while working as much as freedom.
And the end of the lesson, I will give you an overview of what packages and tools we are going to learn
in this course in JDK.
Answering all these questions will give you insights on what we are going to learn in this course.
I believe we are good with our agenda for today.
Let's start and before we even start discussion of multithreaded in the program, let's understand what
the process is in computer science.
In simple words, process is an instance of a computer program.
You opened a glimpse.
It's a separate process to run as a Java program.
Is that a separate Java process?
Computer program is nothing more than a set of instructions for a machine but process.
It is an execution of these instructions.
A process has a self-contained execution environment.
That means that each process has its own memory space.
And as I said before, usually processes and programs are considered to be very close terms.
But what end user interaction with may be a set of processes that interact with each other doing no
such popular Internet browser as Google Chrome?
So long to go home and look at the task manager.
You will see separate processes for each stop in your browser.
But for the end user, Manglehorn perceived like a single application.
This is because most operating system support interpersonal communication resources, sap, pipes and
sockets.
These resources are used to interact between different processes, homes, and this is pretty straightforward.
Now let's understand what threat of execution is.
Each process may be executed in one or more threats of execution.
In this case, our program is executed concurrently.
In other words, some instructions are executed in parallel.
In computer science, concurrency is a duplicate of different parts or units of a program algorithm
or problem to be executed out of order or at the same time simultaneously without affecting the final
outcome.
So we can say that each process may be executed in multiple threats.
In the learning literature, you might even find mention about different name of abstracts.
Sometimes they're called as lightweight processes or threats, share process resources.
This is something that may cause issues during the multithreaded.
If you're allocated two gigabytes for a GBM, that means all created stress will work within these two
gigabytes and we'll share in between each other.
Knowing your memory will be allocated to threat of execution.
I hope you already know the answer to my next question.
What is a move to threaten?
To threaten is the process of execution of program in multiple threats.
Most of the operating systems nowadays support this feature.
You have multiple course in your processa multithreaded allows you to use all course for execution of
your program instructions.
EPU executes one task at a time and we as the software engineers will write instructions how to split
between different threats of execution.
That's what we are going to learn.
Let me explain it now.
How multiscreen program works on the high level, you always have one threat of execution.
One program just started.
That is your main threat of execution.
After that, you can run so-called child threats of execution and describe instructions what those threats
should work on.
In parallel, the different use cases of using Otis Redding.
And we'll look at them in the minute.
And now the important thing, how to synchronize the work of different threats imagines at your peril
to your work between multiple threats.
It is another thing that.
All of the threats are part of one program, and sometimes threat needs to update on the man's threat
about state of execution or result of execution.
But sometimes threats also need to interact with each other, take into account all threats, working
with some shared resource.
To rephrase this in simple words, imagine that you have a collection of users and you need to filter
this collection and remove users that have less than one thousand dollars total.
Check in your online shop and you decided to split the task between different threats of execution.
Each threat of execution works with shared resource collection of users.
Each threat takes users from this common collection to provide the result of the specific part of namely
users are equally distributed between different threats but all threats to removing users from the common
collection shared between all of them.
Can you understand what the shared resource mean on this example?
Let's review also other use cases of multithreaded programming and the one we might want to use this
approach.
I believe that we have already discussed the first case.
That is the case when different threats on these slides are marked with capital key and numbers reaching
out to shared resource that is marked with capital are in this case to modify the state of the resource.
So next year's case of using multithreaded is reading and writing operations.
You know that in Java, most of the input output streams, blogs and in process of execution.
So why don't we use features of malicious reading?
And in case we need to write, let's say, some file, we do this in a separate thread.
For example, a user asked us to do an expert of all users to see format and wants to download this
info.
No problem at all.
We are writing a separate threat of execution and other parts of our program proceed, working without
any free's user still able to click on other buttons and perform other operations while file downloading
is in progress.
Is that clear?
Same situation with redundant info.
Let's create a separate threat of execution that will show a status of uploading, and once uploading
is finished, we will be notified about that fact and we'll proceed from there.
Pay attention to how your clips is working when your important project or performance some other operations.
Eclipse is also Java application was multithreaded feature inside.
When any operation is performed, UI is not completely blocked and you still can perform as operations
with the clips in parallel.
The third case is a case when once to produce some data and other thread consumes this data.
These threads are working independently and potentially may interact with the help of the queue between
each other.
On the slide here you can see that we have producer and consumer producer send some item ready for processing
to the queue and consumer take this item from the queue when ready to process the next item.
The next case is a typical scenario with writers and readers.
Imagine that you have some shared resource, some shared buffer, and from one side you have writers
that might be separate services.
Read that, write some information to the buffer.
It can be is a strong representation of new objects or requests to the app.
Literally everything.
And on the other side, you have readers that read data from the buffer.
This example is different from all previous ones that we have discussed because here we have some specific
conditions on the ones that can write to the buffer at the point of time readers can to read during
the writing, all the readers may read data simultaneously, will have similar tasks in this course.
And I will show you how to solve this task.
Really interesting, don't you think so?
Probably these are the most popular use cases of using an Otis Redding approach.
Definitely there will be variations of these use cases and sometimes even different scenarios, but
we'll try to cover as much as we can on this course.
Now let's discuss advantages and disadvantages of multi threading approach.
Let's start from advantages of multithreaded.
It was to name a few important ones.
They are effective use of multiple course of your processa, high performance of your program during
execution of specific operations and data processing.
Good to use with operations that block mansard of execution.
Like I said before, in case of working with input output streams, application responsiveness, if
there is a need to perform, some operation application won't be frozen until that operation is completed.
Instead, I will execute request in a separate thread.
Probably these are main advantages of using these advantages, maintaining the Australian approach.
Across all over the world and in different programming languages, but there are always two sides of
a metal, all these advantages come with a group of disadvantages.
Some of them are it is easy to use is written incorrectly by saying this, I would like to highlight
that using what is right.
And it requires a good understanding of the toolset to implement concurrent execution of your program.
And that is relatively easy to do.
A mistake, for example, in synchronous court, sometimes also of execution doesn't play a big role.
Or you can write code in different ways with the thread and it is not so easy and straightforward.
You need to be sure about what pieces of code you need to synchronize between different threads, how
much stress you need, how to split work between threads and so on.
Incorrect and suitable usage of Montasser in May cause your performance.
You need to understand that multithreaded works perfectly, not for all tasks.
For example, you might not always see the benefit of using what is written while working with small
data in case you want to implement a certain approach and filter an election was one hundred integers.
More likely, it will take more time than performing the same operation synchronously in one step.
Why?
Because running threads, synchronization time, corporatization of different threads on different CPUs.
All of this takes time and we need to be sure that when we apply to certain approach, it is really
worth it and we will benefit from this and some mistakes even can bring it to the deadlock and lifework
cases.
When your program doesn't perform any useful activity, hard to debark application and find the mistake,
it is much harder to replicate an error in the multithreaded application than it is to do so in a single
threaded application.
As a result, it is more difficult to identify and verify root causes when error.
Secure testing process of multithreaded app is more difficult.
Testing the multithreaded application is more difficult than testing a single application because the
effects are often timing related and more difficult to reproduce.
It is difficult to introduce notice writing approach already created code because all code needs to
be analyzed by engineers, static variables, methods and locations and critical areas.
Everything needs to be reviewed and adjusted to make sure that the implementation of concurrent programming
approach will not affect all application.
The main disadvantages of multithreaded that we also need to consider when we want to create scalable
app with high performance.
In this course, we are going to learn tools for concurrent programming most tools, classes and interfaces
allocated in Java.
You can current package.
This package also has some set packages, also some main types like Runnable and Thread located in general
and package.
But most of the classes and interfaces, including concurrent collections, locks and other mechanisms
for stress synchronization executer services and most of the things that we are going to learn allocated
individual concurrent package.
We have really a lot of interesting things to learn.
Now let's recap what we have learned in this lesson and this lesson.
We learned what the process is and what the threat is.
We also learned what is a multiscreen program programming now, you know, the most popular use cases
of not just training programs.
We learned advantages and disadvantages of concurrent programming.
That's all for this lesson.
Looking forward to seeing you in the next lesson.