我正在尝试实现一个WebLogic作业调度示例,以测试集群在调度任务上的故障转移能力(以确保这些任务在故障转移场景中执行)。
考虑到这一点,我一直在关注
this example
并尝试相应地配置所有内容。以下是我迄今为止所做的步骤:
-
服务器(
管理员服务器
实例(
诺迪
和
史努比
);
-
设置数据库表(使用Oracle)
氙):
ACTIVE
WEBLOGIC_TIMERS
;
-
将其与计划关联
“群集设置”下的任务>
-
执行任务(
TimerListener
和一个
初始化作业
日程安排如下:
.
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() ) );
}
}
}
然后,我执行servlet来启动第一个托管实例上的调度(
服务器),按预期返回:
(Servlet)
执行输出
)
从JNDI初始化计时器
weblogic.scheduler。TimerServiceImpl@43b4c7
启动计时器-状态:
这导致在my DB表中创建了2行:
-
WEBLOGIC\u计时器
servlet执行后的表状态:
“编辑”计时器ID“;”侦听器“;”开始时间“;”间隔“;”计时器\管理器\名称“;”域名“;”“群集名称”;
""; "“诺迪欧1268653040156”[数据类型]“;”1268653040156"; "30000"; "weblogic.JobScheduler“;”myCluster“;”“群集”
-
活跃
servlet执行后的表状态:
“编辑”服务器“;”实例“;”域名“;”俱乐部名称“;”“超时”;
""; "服务。单身主人“;”6382071947583985002/诺迪““群集”群集“;”10.03.15"
但是,作业未按计划执行。它应该在服务器的日志输出上打印一条消息(
Noddy.out
文件),表示计时器已过期。没有。我的日志文件状态如下:
管理服务器
日志(
myCluster.log
文件):
####<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.>
日志
(
点头。出去
文件):
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
文件):
####<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.>