Skip to content →

CRON jobs to free Memory Leaks of web servers

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



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.

As a side node: as with Plesk Obsidian one can visually add CRON jobs in the Tools & Settings menu under the Tools & Ressources Section. It’s called Scheduled Tasks (Cron jobs) .

Published in Server Configuration


Leave a Reply

Your email address will not be published. Required fields are marked *