Some webserver don’t protect well against memory leaks. And the Java garbage collector is not necessarily famous for sweeping properly. Whatever the cause is of the leak, you need to fix it in your code.
As a temporary workaround for an older web service I’ve written – but is not in use anymore – I restarted the web container on a daily basis. Automated with cron of course.
The easiest way to avoid path resolution mistakes is to work with system control
systemctl. Why? Because the executable is already defined in the service definition file (in this case in Ubuntu). In my case that is safed at /etc/systemd/system/wildfly.service
Description=The WildFly Application Server
ExecStart=/opt/wildfly/bin/launch.sh $WILDFLY_MODE $WILDFLY_CONFIG $WILDFLY_BIND
Open the cron file
crontab -e. Add a new line to invoke the systemctl command with the arguments of the service and command.
05 04 * * * systemctl restart wildfly
This cron job will start at 04:05 every day to restart the wildfly service respectively the container. This will free blocked memory availability. Anyhow, an increase of requests might still block the server