Image of How to schedule a tomcat service restart in windows

ADVERTISEMENT

Introduction

This tutorial provides a step-by-step guide on how to create a windows task which restarts the tomcat service at a specific time frame.

1. Create a batch file for stopping/starting tomcat

The first step is to create a batch script that stops and starts the tomcat service through the tomcat service name, this tutorial describes in detail how to do this.

2. Create windows scheduler

In order to run the above script automatically, we create a windows task through the following steps:

  • Go to Start => Task Scheduler
  • Right-click “Task Scheduler Library” => “Create Basic Task”
  • Name the task as “Tomcat Restart”, write some description then click Next.

Create basic task in windows

  • In the trigger screen, select when do you want this task to run, in our example, we select “Daily”.
  • In the next screen, set the time at which the task executes and keep the “Recur every” field as 1 day, then click Next.

Create daily basic task in windows

  • Keep the action as “Start a program”, then click Next.
  • Now put the path of your batch script and keep the optional fields empty, then click Next

Set the program to run in the windows task screen

  • In the last screen, check on “Open the properties dialog for this task ..” checkbox then click Finish.
  • After clicking “Finish“, the “Task Properties” screen appears. In the “Security Options” section, tick on the “Run whether user is logged on or not” radio button and check on the “Run with highest privileges” checkbox as below:

Windows task properties

  • Finally, go to the “Settings” tab and check the “If the task fails, restart every” checkbox and set how much time windows should wait before running the task again in case of failure. This step is very important because by default the task won’t run again after failure.

Windows task failure

Summary

This tutorial provides a step-by-step guide on how to create a windows task which restarts the tomcat service at a specific time frame.

Next Steps

If you're interested in learning more about the basics of Java, coding, and software development, check out our Coding Essentials Guidebook for Developers, where we cover the essential languages, concepts, and tools that you'll need to become a professional developer.

Thanks and happy coding! We hope you enjoyed this article. If you have any questions or comments, feel free to reach out to jacob@initialcommit.io.