Scheduling a batch file every 10 seconds

Recently while investigating high cpu issues in an web application, I wanted to take thread dumps (through jstack) every 10 seconds. First thought was to schedule the batch file through a task scheduler, but I realized that with the task scheduler you cannot set a repetition interval lower then a minute.

An alternative approach would be to use a ping command in the batch file.

jstack <process-id>     &:: Add your command here.
ping localhost -n 11 > nul
goto loop

The ping command will execute for 10 seconds, and all the output will be redirected to the NUL device, meaning that you will see no output from the ping command. It works indeed as a “sleep” command would.


Posted on September 7, 2012, in windows and tagged , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: