title: Wicket Application, Serialization and Java Timers
body: <p>So I have somewhat limited experience with serialization, Wicket, and multi thread projects so bear with me.</p>
  
  <p>Essentially my web application class is instantiating a POJ (parentObject) which creates a starts a new timer and instantiates several childObjects that also have timers in them. These childObjects are stored in a list in the parentObject class. Pages in my wicket application need to access parentObject, so I made it accessible as so:</p>
  
  <pre><code>public Object getParentObject
  {
     return this.parentObject;
  }
  </code></pre>
  
  <p>And it is retrieved in each page like so:</p>
  
  <pre><code>((MyApplication)Application.get()).getParentObject()
  </code></pre>
  
  <p>The problem currently is that the timertask for both the parentObject and childObjects are no longer being called every minute as they should be. My logs pick up the first start of the parentObject, but the logging message is never outputted again signalling that the run() method of parent Object's timertask is not being executed every minute.</p>
  
  <p>EDIT: Added some more code to make it more clear the issue</p>
  
  <pre><code>public class childObject implements Serializable
  {
      private transient NamedParameterJdbcTemplate njt;
      private transient Timer timer;
  
      public childObject(DataSource ds)
      {
          this.njt = new NamedParamterJdbcTemplate(ds);
      }
  
      public void start()
      {
          timer = new Timer();
  
          timer.schedule(new TimerTask(){
  
              public void run()
              {
                  //do some stuff that is never happening
              }
  
          }, 0, 60000);
      }
  }
  
  public class ParentObject implements Serializable
  {
      private DataSource ds;
      private List&lt;ChildObject&gt; childObjects;
      private transient Timer;
  
      public ParentObject(DataSource ds)
      {
          this.ds = ds;
          //add some stuff to childObjects
  
          timer = new Timer();
  
          timer.schedule(new TimerTask(){
  
              public void run()
              {
                  for(some condition)
                  {
                      //Do some stuff
  
                      if(/*condition is met*/)
                      {
                          childObjects.get(i).start();
                      }
                  }
              }
  
          }, 0, 60000);
      }
  }
  
  public MyApplication extends WebApplication
  {
      private ParentObject object;
      private DataSource ds;
  
      public void init()
      {
          super.init();
  
          ApplicationContext context = new ClassPathXmlApplicationContext("/applicationContext.xml");
          ds = (DataSource) context.getBean("dataSource");
  
          parentObject = new ParentObject(ds);
      }
  }
  </code></pre>