This week's book giveaway is in the Other Languages forum. We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line! See this thread for details.
The main thing to remember is that with multiple threads you've got very little control over the scheduling (unless you intervene with synchronized blocks or other mechanisms). The priorities are just a hint to the scheduler, but they may or may not have a great effect. In fact, you can potentially get very different results running the program twice with the same priorities.
The key thing to take away from this is to never make assumptions over how the threads will be handled when left to their own devices. If the order really matters to your application, you need to design that in.
I wrote this code
When I see the output its different everytime(even if we ignore the if loops)
Now my question is lets say a scenario
where three threads are downloading different files of size 2, 8 and 20 MB
I want the logic that the thread downloading the smallest file should get more priority
Is above logic the right way to implement the same?