oracle WebLogic 作业调度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2446880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 20:13:03  来源:igfitidea点击:

WebLogic job scheduling

oracleservletsweblogicscheduled-tasks

提问by XpiritO

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).

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

With this in mind, I've been following this exampleand trying to configure everything accordingly. Here are the steps I've done so far:

考虑到这一点,我一直在关注这个示例并尝试相应地配置所有内容。以下是我到目前为止所做的步骤:

  1. Configured a cluster with 1 admin server (AdminServer) and 2 managed instances (Noddyand Snoopy);
  2. Set up database tables (using Oracle XE): ACTIVEand WEBLOGIC_TIMERS;
  3. Set up data source to access DB and associated it to the scheduling tasks under "Settings for cluster" > "Scheduling";
  4. Implemented a job (TimerListener) and a servletto initialize the job scheduling, as follows:
  1. 使用 1 个管理服务器 ( AdminServer) 和 2 个托管实例(NoddySnoopy)配置集群;
  2. 设置数据库表(使用 Oracle XE):ACTIVEWEBLOGIC_TIMERS
  3. 在“集群设置”>“调度”下设置访问数据库的数据源并将其关联到调度任务;
  4. 实现了一个job( TimerListener)和一个servlet来初始化job调度,如下:

.

.

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 (Noddyserver), which returned as expected:

然后我执行 servlet 以在第一个托管实例(Noddy服务器)上开始调度,它按预期返回:

(Servlet execution output)

(Servlet执行输出

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:

service() 进入 try 块以从 JNDI 初始化计时器

jobScheduler 参考 weblogic.scheduler.TimerServiceImpl@43b4c7

定时器预定!

service() 启动定时器

启动计时器 - 状态:

Which resulted in the creation of 2 rows in my DB tables:

这导致在我的数据库表中创建了 2 行:

  • WEBLOGIC_TIMERStable 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"

  • ACTIVEtable state after servlet execution:

    "EDIT"; "SERVER"; "INSTANCE"; "DOMAINNAME"; "CLUSTERNAME"; "TIMEOUT";

    ""; "service.SINGLETON_MASTER"; "6382071947583985002/Noddy"; "QRENcluster"; "Cluster"; "10.03.15"

  • WEBLOGIC_TIMERSservlet 执行后的表状态:

    “编辑”; "TIMER_ID"; “听者”;“开始时间”; “间隔”; "TIMER_MANAGER_NAME"; "DOMAIN_NAME"; "CLUSTER_NAME";

    ""; "Noddy_1268653040156"; “[数据类型]”; "1268653040156"; "30000"; "weblogic.JobScheduler"; “我的集群”;“簇”

  • ACTIVEservlet 执行后的表状态:

    “编辑”; “服务器”; “实例”; "域名"; "集群名"; “暂停”;

    ""; "service.SINGLETON_MASTER"; "6382071947583985002/Noddy"; "QRENcluster"; “簇”; “10.03.15”

Although, the job is not executed as scheduled. It should print a message on the server's log output (Noddy.outfile) with a timestamp, saying that the timer had expired. It doesn't. My log files state as follows:

虽然,作业没有按计划执行。它应该在服务器的日志输出(Noddy.out文件)上打印一条带有时间戳的消息,表示计时器已过期。它没有。我的日志文件状态如下:

Admin serverlog (myCluster.logfile):

管理服务器日志(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.> 

Noddy serverlog (Noddy.outfile):

Noddy 服务器日志(Noddy.out文件):

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.logfile):

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.> 

Can anyone help me out discovering what's wrong with my configuration? Thanks in advance for your help!

任何人都可以帮助我发现我的配置有什么问题吗?在此先感谢您的帮助!

采纳答案by XpiritO

I turned out to solve this problem by restarting the whole system and then starting WebLogic instances from the command line. In this perspective I managed to get this into working, with the output being sent to the command line.

我原来是通过重新启动整个系统然后从命令行启动 WebLogic 实例来解决这个问题的。从这个角度来看,我设法让它发挥作用,将输出发送到命令行。

I'd like to thank everyone who tried to help me solving this one.

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

回答by Radek Skokan

Also try to add the debug (JAVA_OPTIONS: -Dweblogic.debug.DebugSingletonServices=true -Dweblogic.JobScheduler=true)

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

For me, it was not enough to put it just in the server startup params via Console. I had to put in setDomainEnv.sh.

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