Computers typically run with a single task, which means that they can usually execute one command at a time on a processor or core.
However, as you noticed, your operating system (and other programs) seems to run many tasks at the same time.
This is achieved by dividing the work into processes, and each process can additionally implement concurrency by spawning threads. The operating system then quickly switches between each process and thread to create the illusion of multitasking.
In your situation, your java program is one process, and you will need to create 4 threads, each of which will start its own loop. This can be tricky because threads must synchronize their access to local variables to prevent one variable from being edited while another thread is trying to access it.
Since threads are a complex subject, this will require much more explanation than I can do here.
However, you can read Suns' excellent Concurrency tutorial, which covers everything you need to know:
http://java.sun.com/docs/books/tutorial/essential/concurrency/
source share