首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WebLogic作业调度

WebLogic作业调度
EN

Stack Overflow用户
提问于 2010-03-15 12:03:05
回答 2查看 14.7K关注 0票数 2

我正在尝试实现一个WebLogic作业调度示例,以测试我的集群在计划任务上发生故障转移的能力(以确保这些任务在故障转移场景中得到执行)。

考虑到这一点,我一直在跟踪这个例子,并试图相应地配置所有内容。以下是我迄今为止所做的步骤:

  1. 配置了一个包含1个管理服务器(AdminServer)和2个托管实例(Noddy和Snoopy)的集群;
  2. 建立数据库表(使用Oracle ):ACTIVEWEBLOGIC_TIMERS
  3. 设置数据源访问DB并将其与“集群设置”>“调度”下的调度任务相关联;
  4. 实现一个作业(TimerListener)和一个servlet来初始化作业调度,如下所示:

代码语言:javascript
复制
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以启动第一个托管实例(Noddy服务器)上的调度,该实例按预期返回:

(Servlet执行输出)

service()输入try块,使JNDI中的计时器无效 jobScheduler参考weblogic.scheduler.TimerServiceImpl@43b4c7 计时器预定好了! service()启动计时器 启动计时器状态:

这导致在我的DB表中创建了2行:

  • servlet执行后的WEBLOGIC_TIMERS表状态: “编辑”;"TIMER_ID";“听者”;"START_TIME";"INTERVAL";"TIMER_MANAGER_NAME";"DOMAIN_NAME";"CLUSTER_NAME"; "";"Noddy_1268653040156";“数据类型”;"1268653040156";"30000";"weblogic.JobScheduler";"myCluster";“群集”
  • servlet执行后的ACTIVE表状态: “编辑”;“服务器”;“实例”;"DOMAINNAME";"CLUSTERNAME";“超时”; "";"service.SINGLETON_MASTER";"6382071947583985002/Noddy";"QRENcluster";“群集”;"10.03.15“

不过,作业没有按计划执行。它应该用时间戳在服务器的日志输出(Noddy.out文件)上打印一条消息,上面写着计时器过期了。它没有。我的日志文件声明如下:

管理服务器日志(myCluster.log文件):

代码语言:javascript
复制
####<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服务器日志(Noddy.out文件):

代码语言:javascript
复制
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文件):

代码语言:javascript
复制
####<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.> 

有人能帮我发现我的配置有什么问题吗?提前感谢您的帮助!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-03-22 15:14:08

我原来是通过重新启动整个系统,然后从命令行启动WebLogic实例来解决这个问题的。在这个透视图中,我成功地将输出发送到命令行,从而使其正常工作。

我要感谢所有试图帮我解决这个问题的人。

票数 1
EN

Stack Overflow用户

发布于 2011-04-20 15:02:08

还尝试添加调试(JAVA_OPTIONS:-Dweblogic.debug.DebugSingletonServices=true -Dweblogic.JobScheduler=true)

对我来说,仅仅通过控制台将其放在服务器启动参数中是不够的。我不得不加入setDomainEnv.sh。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2446880

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档