You probably can come up with 100 hacky ways to do that, but I can see only 2 ways in a properly designed application.
It's a break from processing code.
while (acceptNextRequest()) {
// Processing code
if (shouldExitNow()) {
break;
}
// More processing
}
// Proper exiting code
Check if it's time to exit before accepting next request:
while (!shouldExitBeforeNextRequest() && acceptNextRequest()) {
// Processing code
}
// Proper exiting code
Both solutions ensure proper closing of all connections, notifications to all application close listeners, etc.
If you do System.exit() from a web application, you will close entire web server application (Tomcat, JBoss or whatever use), which is usually not something you want to do from within your application.
And don't mess with the main thread if you run your application in a container.