For this you should use a threaded loop. A thread is a subprosses. This allows a program to do multiple things at once.
And you should use something else then thread.sleep(); because these could be...