aspose file tools*
The moose likes Java in General and the fly likes What is the Linux command to find the created timer daemon Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "What is the Linux command to find the created timer daemon" Watch "What is the Linux command to find the created timer daemon" New topic
Author

What is the Linux command to find the created timer daemon

Raymond Rugemalira
Greenhorn

Joined: Nov 14, 2008
Posts: 2
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

Joined: Aug 16, 2005
Posts: 14269
    
  21

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Raymond Rugemalira
Greenhorn

Joined: Nov 14, 2008
Posts: 2
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: What is the Linux command to find the created timer daemon