title: WebLogic job scheduling
body: <p>I'm trying to implement a WebLogic job scheduling example, to test my cluster capabilities of fail-over on scheduled tasks (to ensure that these tasks are executed on fail over scenario).</p>
  
  <p>With this in mind, I've been following <a href="http://blogs.oracle.com/jamesbayer/2009/04/a_simple_job_scheduler_example.html" rel="nofollow noreferrer">this example</a> and trying to configure everything accordingly. Here are the steps I've done so far:</p>
  
  <ol>
  <li>Configured a cluster with 1 admin
  server (<em>AdminServer</em>) and 2 managed
  instances (<em>Noddy</em> and <em>Snoopy</em>);</li>
  <li>Set up database tables (using Oracle
  XE): <code>ACTIVE</code> and <code>WEBLOGIC_TIMERS</code>;</li>
  <li>Set up data source to access DB and
  associated it to the scheduling
  tasks under "Settings for cluster" >
  "Scheduling";</li>
  <li>Implemented a job (<code>TimerListener</code>)
  and a <em>servlet</em> to initialize the job
  scheduling, as follows:</li>
  </ol>
  
  <p>.</p>
  
  <pre><code>package timedexecution;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.io.Serializable;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import commonj.timers.Timer;
  import commonj.timers.TimerListener;
  import commonj.timers.TimerManager;
  
  public class TimerServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      protected static void logMessage(String message, PrintWriter out){
          out.write("&lt;p&gt;"+ message +"&lt;/p&gt;");
          System.out.println(message);
      }
  
      @Override
      public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          PrintWriter out = response.getWriter();
          //
          out.println("&lt;html&gt;");
          out.println("&lt;head&gt;&lt;title&gt;TimerServlet&lt;/title&gt;&lt;/head&gt;");
          //
          try {
              //
              logMessage("service() entering try block to intialize the timer from JNDI", out);
              //
              InitialContext ic = new InitialContext();
              TimerManager jobScheduler = (TimerManager)ic.lookup("weblogic.JobScheduler");
              //
              logMessage("jobScheduler reference " + jobScheduler, out);
              //
              jobScheduler.schedule(new ExampleTimerListener(), 0, 30*1000);            
              //
              logMessage("Timer scheduled!", out);
              //
              //execute this job every 30 seconds
              logMessage("service() started the timer", out);
              //
              logMessage("Started the timer - status:", out);
              //
          }
          catch (NamingException ne) {
              String msg = ne.getMessage();
              logMessage("Timer schedule failed!", out);
              logMessage(msg, out);
          }
          catch (Throwable t) {
              logMessage("service() error initializing timer manager with JNDI name weblogic.JobScheduler " + t,out);
          }
          //
          out.println("&lt;/body&gt;&lt;/html&gt;");
          out.close();
      }
  
  
      private static class ExampleTimerListener implements Serializable, TimerListener {
          private static final long serialVersionUID = 8313912206357147939L;
  
          public void timerExpired(Timer timer) {
              SimpleDateFormat sdf = new SimpleDateFormat();
              System.out.println( "timerExpired() called at " + sdf.format( new Date() ) );
          }
      }
  
  }
  </code></pre>
  
  <p>Then I executed the servlet to start the scheduling on the first managed instance (<em>Noddy</em> server), which returned as expected:</p>
  
  <p>(Servlet <em>execution output</em>)</p>
  
  <blockquote>
    <p>service() entering try block to
    intialize the timer from JNDI</p>
    
    <p>jobScheduler reference
    weblogic.scheduler.TimerServiceImpl@43b4c7</p>
    
    <p>Timer scheduled!</p>
    
    <p>service() started the timer</p>
    
    <p>Started the timer - status:</p>
  </blockquote>
  
  <p>Which resulted in the creation of 2 rows in my DB tables:</p>
  
  <ul>
  <li><p><code>WEBLOGIC_TIMERS</code> table state after servlet execution:</p>
  
  <p>"EDIT"; "TIMER_ID"; "LISTENER"; "START_TIME"; "INTERVAL"; "TIMER_MANAGER_NAME"; "DOMAIN_NAME"; "CLUSTER_NAME";</p>
  
  <p>""; "Noddy_1268653040156"; "[datatype]"; "1268653040156"; "30000"; "weblogic.JobScheduler"; "myCluster"; "Cluster"</p></li>
  <li><p><code>ACTIVE</code> table state after servlet execution:</p>
  
  <p>"EDIT"; "SERVER"; "INSTANCE"; "DOMAINNAME"; "CLUSTERNAME"; "TIMEOUT";</p>
  
  <p>""; "service.SINGLETON_MASTER"; "6382071947583985002/Noddy"; "QRENcluster"; "Cluster"; "10.03.15"</p></li>
  </ul>
  
  <p>Although, the job is not executed as scheduled. It should print a message on the server's log output (<code>Noddy.out</code> file) with a timestamp, saying that the timer had expired. It doesn't. My log files state as follows:</p>
  
  <p><em>Admin server</em> log (<code>myCluster.log</code> file):</p>
  
  <pre><code>####&lt;15/Mar/2010 10H45m GMT&gt; &lt;Warning&gt; &lt;Cluster&gt; &lt;test-ad&gt; &lt;Noddy&gt; &lt;[STANDBY] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'&gt; &lt;&lt;WLS Kernel&gt;&gt; &lt;&gt; &lt;&gt; &lt;1268649925727&gt; &lt;BEA-000192&gt; &lt;No currently living server was found that could host TimerMaster. The server will retry in a few seconds.&gt; 
  </code></pre>
  
  <p><em>Noddy server</em> log
  (<code>Noddy.out</code> file):</p>
  
  <pre><code>service() entering try block to intialize the timer from JNDI
  jobScheduler reference weblogic.scheduler.TimerServiceImpl@43b4c7
  Timer scheduled!
  service() started the timer
  Started the timer - status:
  &lt;15/Mar/2010 10H45m GMT&gt; &lt;Warning&gt; &lt;Cluster&gt; &lt;BEA-000192&gt; &lt;No currently living server was found that could host TimerMaster. The server will retry in a few seconds.&gt; 
  </code></pre>
  
  <p>(<code>Noddy.log</code> file):</p>
  
  <pre><code>####&lt;15/Mar/2010 11H24m GMT&gt; &lt;Info&gt; &lt;Common&gt; &lt;test-ad&gt; &lt;Noddy&gt; &lt;[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'&gt; &lt;&lt;WLS Kernel&gt;&gt; &lt;&gt; &lt;&gt; &lt;1268652270128&gt; &lt;BEA-000628&gt; &lt;Created "1" resources for pool "TxDataSourceOracle", out of which "1" are available and "0" are unavailable.&gt; 
  ####&lt;15/Mar/2010 11H37m GMT&gt; &lt;Info&gt; &lt;Cluster&gt; &lt;test-ad&gt; &lt;Noddy&gt; &lt;[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'&gt; &lt;&lt;anonymous&gt;&gt; &lt;&gt; &lt;&gt; &lt;1268653040226&gt; &lt;BEA-000182&gt; &lt;Job Scheduler created a job with ID Noddy_1268653040156 for TimerListener with description timedexecution.TimerServlet$ExampleTimerListener@2ce79a&gt; 
  ####&lt;15/Mar/2010 11H39m GMT&gt; &lt;Info&gt; &lt;JDBC&gt; &lt;test-ad&gt; &lt;Noddy&gt; &lt;[ACTIVE] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'&gt; &lt;&lt;WLS Kernel&gt;&gt; &lt;&gt; &lt;&gt; &lt;1268653166307&gt; &lt;BEA-001128&gt; &lt;Connection for pool "TxDataSourceOracle" closed.&gt; 
  </code></pre>
  
  <p>Can anyone help me out discovering what's wrong with my configuration? Thanks in advance for your help!</p>