Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the Linux command to find the created timer daemon

 
Raymond Rugemalira
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a ServletListener with which I create a timer object Timer timer = new Timer(timerName, true).
I define a timer task TimerTask task = new TimerTask() { ...};
I schedule the task for repeated fixed rate execution as follows:
timer.scheduleAtFixedRate(task, initialDelay, thePeriod);
and at boot a timer daemon thread is created.

PROBLEM (QUESTION):
How do I determine that the daemon thread is indeed created? Which command do I use to find the created timer, and daemon thread? Where is the information about the timer and the daemon kept?

I'd appreciate your quick reply. Thank you.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

You have a reference to the Timer object, and also to the TimerTask object.

If you can create the Timer and schedule a TimerTask with it and no exceptions happen, then you know that creating the timer thread succeeded.

What do you mean by "Linux command"? Are you looking for some Linux shell command to check if the timer thread exists? The timer thread is a thread inside the JVM of your running program, not something that runs separately from your program. Note that if your program exits, all daemon threads inside your program stop too.

I suspect that you created a program that schedules a timer task and that then exits, and you seem to expect that even after your program has stopped the timer is still running somewhere and the task will run when it is time. That is not the case.
 
Raymond Rugemalira
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. In fact I have an application on the glassfish application server.

When the application server is started at boot,a ServletContextListener is executed and the context is initialized so that a timer is scheduled for a particular task to be executed repeatedly after a known long period.

I'm assuming the task will be executed repeatedly according to schedule as long as my application server is up and running. Is my assumption correct? This is the first time I use a ServletContextListener to schedule a timer and accompanying task therefore the query. I do appreciate your input. Kindly let me know whether my reasoning is correct.


Jesper de Jong wrote:Welcome to the Ranch.

You have a reference to the Timer object, and also to the TimerTask object.

If you can create the Timer and schedule a TimerTask with it and no exceptions happen, then you know that creating the timer thread succeeded.

What do you mean by "Linux command"? Are you looking for some Linux shell command to check if the timer thread exists? The timer thread is a thread inside the JVM of your running program, not something that runs separately from your program. Note that if your program exits, all daemon threads inside your program stop too.

I suspect that you created a program that schedules a timer task and that then exits, and you seem to expect that even after your program has stopped the timer is still running somewhere and the task will run when it is time. That is not the case.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic