Learning Programming #2.4 Learning Java: Multithreadding

in programming •  6 years ago 

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!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @quantumdeveloper! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You got more than 400 replies. Your next target is to reach 500 replies.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

You can upvote this notification to help all Steem users. Learn how here!