WebLogic job scheduling
Posted
by XpiritO
on Stack Overflow
See other posts from Stack Overflow
or by XpiritO
Published on 2010-03-15T12:03:05Z
Indexed on
2010/03/16
11:26 UTC
Read the original article
Hit count: 767
Hello, overflowers :)
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).
With this in mind, I've been following this example and trying to configure everything accordingly. Here are the steps I've done so far:
- Configured a cluster with 1 admin server (AdminServer) and 2 managed instances (Noddy and Snoopy);
- Set up database tables (using Oracle
XE):
ACTIVE
andWEBLOGIC_TIMERS
; - Set up data source to access DB and associated it to the scheduling tasks under "Settings for cluster" > "Scheduling";
- Implemented a job (
TimerListener
) and a servlet to initialize the job scheduling, as follows:
.
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("<p>"+ message +"</p>");
System.out.println(message);
}
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
//
out.println("<html>");
out.println("<head><title>TimerServlet</title></head>");
//
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("</body></html>");
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() ) );
}
}
}
Then I executed the servlet to start the scheduling on the first managed instance (Noddy server), which returned as expected:
(Servlet execution output)
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:
Which resulted in the creation of 2 rows in my DB tables:
WEBLOGIC_TIMERS
table state after servlet execution:"EDIT"; "TIMER_ID"; "LISTENER"; "START_TIME"; "INTERVAL"; "TIMER_MANAGER_NAME"; "DOMAIN_NAME"; "CLUSTER_NAME";
""; "Noddy_1268653040156"; "[datatype]"; "1268653040156"; "30000"; "weblogic.JobScheduler"; "myCluster"; "Cluster"
ACTIVE
table state after servlet execution:"EDIT"; "SERVER"; "INSTANCE"; "DOMAINNAME"; "CLUSTERNAME"; "TIMEOUT";
""; "service.SINGLETON_MASTER"; "6382071947583985002/Noddy"; "QRENcluster"; "Cluster"; "10.03.15"
Although, the job is not executed as scheduled. It should print a message on the server's log output (Noddy.out
file) with a timestamp, saying that the timer had expired. It doesn't. My log files state as follows:
Admin server log (myCluster.log
file):
####<15/Mar/2010 10H45m GMT> <Warning> <Cluster> <test-ad> <Noddy> <[STANDBY] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1268649925727> <BEA-000192> <No currently living server was found that could host TimerMaster. The server will retry in a few seconds.>
Noddy server log
(Noddy.out
file):
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:
<15/Mar/2010 10H45m GMT> <Warning> <Cluster> <BEA-000192> <No currently living server was found that could host TimerMaster. The server will retry in a few seconds.>
(Noddy.log
file):
####<15/Mar/2010 11H24m GMT> <Info> <Common> <test-ad> <Noddy> <[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1268652270128> <BEA-000628> <Created "1" resources for pool "TxDataSourceOracle", out of which "1" are available and "0" are unavailable.>
####<15/Mar/2010 11H37m GMT> <Info> <Cluster> <test-ad> <Noddy> <[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <> <1268653040226> <BEA-000182> <Job Scheduler created a job with ID Noddy_1268653040156 for TimerListener with description timedexecution.TimerServlet$ExampleTimerListener@2ce79a>
####<15/Mar/2010 11H39m GMT> <Info> <JDBC> <test-ad> <Noddy> <[ACTIVE] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1268653166307> <BEA-001128> <Connection for pool "TxDataSourceOracle" closed.>
Can anyone help me out discovering what's wrong with my configuration? Thanks in advance for your help!
© Stack Overflow or respective owner