You can shut it down by executing kill -HUP processId
If there is a need to gracefully finalize work, register your shutdown hook and perform all required finalization there.
More info here Runtime.addShutdownHook
P.S: In my opinion, do not embed web server just for this purpose if you do not really need it. And if you use web server, you need also think about security - anyone who knows the url, can shut your app down remotely:)