Starting out with Java Multi Threading

Multithreading is based on simple concepts we face in our day to day life, big complex terms and definitions make it look like a puzzle not worth solving. This is an effort to make these terms understandable by giving simple examples.
A thread is a flow of execution and in a java application a number of threads might be spawned to accomplish different tasks.
So what’s so special about these threads? Earlier we use to have only single core processors and even though you might have multiple threads created only one ran at a time, the processor context switched the threads simply explained it executed one thread got it out and replaced it with another thread.
Things became interesting when multi-core processors came into being, now threads were running into their own cores, and we had unseen consequences, example with a balance on 100 dollar in an bank account if you did try to checkout two 100$ sums at the same time theoretically it was possible. A lot of scenarios can be thought of where your program will fail its normal course of action.
Also, multiple cores give you a lot of power to divide and conquer tasks which require a lot of processing. You can make things work smoother and faster.
With great power comes great responsibility .aka. Spiderman rule, as in the example of balance, we need co-ordination between threads to perform the operations smoothly. There are terms which you might encounter likedeadlock, the traffic does not move cause both goats on bridge coming from opposite directions are struck in the middle and the bridge is just a log.Starvation when you keep eating the processors, without your other friends getting a chance. Race Condition (Unpredictability) when you call your friend to McDonalds but which one creates confusion, he comes at A and you reach B. Then he returns to check at B and you left to check to check at A.

Comments

Popular posts from this blog

Java Interview : Threads

Spring Framework Interview Notes : Part Two Wiring

Card Dealer In Java in Less than 5 minutes