title: Accessing running task scheduled with java.util.Timer
body: <p>I'm working on a Java project where I have created a class that looks like this (abridged version):</p>
  
  <pre><code>public class Daemon {
    private static Timer[] timerarray=null;
    private static Daemon instance=null;
  
    protected Daemon() {
      ArrayList&lt;Timer&gt; timers = new ArrayList&lt;Timer&gt;();
      Timer t = new Timer("My application");
      t.schedule(new Worker(), 10000,30000);
      timers.add(t);
      //...
      timerarray = timers.toArray(new Timer[]{});
    }
    public static Daemon getInstance() { 
      if(instance==null) instance=new Daemon(); 
      return instance;
    }
    public SomeClass getSomeValueFromWorker(int i) {
      if(timerarray==null || i&gt;=timerarray.length) return null;
      /* 
       * **HOW TO ACCESS THE Worker INSTANCE IN THE Timer ARRAY HERE!? **
       */
      return theValue;
    }
  
    /////////////////////////////////////////////
    private class Worker extends TimerTask {
      public Worker() {}
      public void run() {
        // do some work
      }
      public SomeReturnClass someMethod(SomeType someParameter) {
        //
        return something;
      }
    }
    /////////////////////////////////////////////
  }
  </code></pre>
  
  <p>I start this class, e.g. by invoking <code>daemon.getInstance();</code>.</p>
  
  <p>However, I'd like to have some way to access the running task objects' methods (for example, for monitoring the objects' state). 
  The Java class <code>java.util.Timer</code> does not seem to provide the means to access the running object, it just schedules the object instance extending <code>TimerTask</code>.</p>
  
  <p>Are there ways to access the "running" object instanciated within a <code>Timer</code>? Do I have to subclass the <code>Timer</code> class with the appropriate methods to somehow access the instance (this "feels" strange, somehow)? 
  I suppose someone might have done this before ... where can I find examples of this "procedure"?</p>
  
  <p>Thank you in advance for your feedback.</p>