You'll need to create an entry point in your application to be able to set it to false. Two obvious ways are:
1) let the program use a server socket, then let another application send a quit command to this server socket. If this quit command is received the flag needs to be set to false. Note that the flag needs to be a volatile instance field, declared outside the method. The volatile is required to ensure that the thread that executes this loop doesn't use a cached value that never changes.
2) let the program use a specific file; in Linux and Unix these are called lock files. Let the application create it when it starts. The test then becomes (lockFile.exists() could also have been used). If you delete the lock file the loop will end after its current iteration.