Java Reference
In-Depth Information
Figure 5—Various threads executing code
But in fact that's not the case; the computer can be running a bunch of dif-
ferent threads of execution, apparently all at the same time. Can our code
work that way? What would happen to our code if it were run by multiple
threads?
If you're using only local variables and aren't trying to change anything in
common in the Minecraft world, that would probably be fine—each version
of the code as it's running would have its own copy of variables, and no harm
done. But what if you're using a static variable, something like a big HashMap
to keep track of players and values? Then you have two bits of code reading
and writing from it at the same time, and that generally leads to disaster.
 
 
 
Search WWH ::




Custom Search