Learning Programming #2.4 Learning Java: Multithreadding

Words
176
Reading
1 min
Listen
Play
7y

The processor of your computer should have something like 4 cores.
Those 4 different cores are able to work parallel.
So when you have a task that can be divided into smaller independent packages of work, it can be a huge advantage to make use of multiple cores of your processor.

In java it is quite easy to use multiple cores. All you need to do is creating a new Thread(that's how the individual parts of your program that are distributed on multiple cores are called.) and tell the new Thread what it should do. There are two ways you could do this. And both of them involve object orientation:
Screenshot from 2019-06-23 16-16-08.png

When counting your threads to keep up with the processor count of your computer you need to keep in mind that the main thread(the one that calls the static void main(…)) is also a thread!

Also you should keep in mind that variables from one thread won't be passed to another thread immediately! So when you need to share data between the threads you need to be careful!

Learning Programming #2.4 Learning Java: Multithreadding | Ecency