淘宝开源项目TbSchedule的部署和使用

转载 2016年08月28日 18:10:09

tbschedule项目其实可以分为两部分:

  1. schedule管理控制台。负责控制、监控任务执行状态
  2. 实际执行job的客户端程序。

在实际使用时,首先要启动zookeeper, 然后部署tbschedule web界面的管理控制台,最后启动实际执行job的客户机器。这里zookeeper并不实际控制任务调度,它只是负责与N台执行job的客户端通讯,协调、管理、监控这些机器的运行信息。实际分配任务的是tbschedule管理控制台,控制台从zookeeper获取job的运行信息。

tbSchedule通过控制ZNode的创建、修改、删除来间接控制Job的执行,执行Job的客户端会监听它们对应ZNode的状态更新事件,从而达到通过tbSchedule控制Job执行的目的。

部署zookeeper

http://zookeeper.apache.org/releases.html#download下载最新稳定版本。下载完成后解压,将 /conf目录下的XXX.cfg更名为zoo.cfg,因为zookeeper启动时会在这个目录下找zoo.cfg读取配置信息。这个文件里有几个重要的参数需要说明一下:

  • tickTime=2000 
    • 定义时间计量单位。这里表示一个tick为2秒。以后在配置时间相关的东西时,都是以tick为单位的。
  • dataDir=/tmp 
    • 定义快照(snapshot)文件的存储位置。zookeeper会将节点信息定时写入到这个目录中。这个目录必须存在,否则启动时会报错。
  • clientPort=2181 
    • 指定客户端连接端口。 zookeeper会在这个端口监听连接请求。
  • server.1=127.0.0.1:2000:3000 
    • 这个参数仅在集群部署时起作用。格式为:server.id=host:port:portid表示服务器的唯一标识,一般从1开始计数。第一个port表示zookeeper集群机器之间的通讯端口,第二个port表示当集群机器在选举leader时使用的通讯端口。只有当集群第一次启动,或master机崩溃时,才会进行leader选举。

配置完成后,切换到/bin目录,执行:

<code class=" hljs sql" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: Arial, Helvetica, sans-serif;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background: transparent;"><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">./</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">zkServer</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">.</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">sh </span><span class="hljs-operator" style="box-sizing: border-box; padding: 0px;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;"><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">start</span></span></span></code>

即可启动zookeeper,默认会在后台运行,如果想在前端运行,需要执行:

<code class=" hljs sql" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: Arial, Helvetica, sans-serif;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background: transparent;"><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">./</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">zkServer</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">.</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">sh </span><span class="hljs-operator" style="box-sizing: border-box; padding: 0px;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;"><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">start</span></span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">-</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">foreground</span></span></code>

Zookeeper集群部署

集群部署时,除了需要指定zoo.cfgserver.X:XXXX:XX:XX参数外,还要在每台机器的dataDir目录下创建一个名为myid的文件,内容为当前机器的标识数字,与server.X中的X相同。完成配置后,依次启动每个zookeeper即可。 
注意,当你在启动第一个zookeeper时控制台会大量报错,这是因为其它的zookeeper还没有启动。无视即可。

tbSchedule控制台部署

tbSchedule就是个用servlet/JSP 写的web项目,我们可以直接把war包部署到tomcat中,然后在浏览器访问

<code class=" hljs cs" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: Arial, Helvetica, sans-serif;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background: transparent;"><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">http</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">:</span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box; padding: 0px;">//localhost:8080/ScheduleConsole</span></code>

即可。 
如果你想手动编译、构建项目而不是使用war包,要小心一个坑,那就是执行

<code class=" hljs lasso" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: Arial, Helvetica, sans-serif;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background: transparent;"><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">mvn clean install </span><span class="hljs-attribute" style="box-sizing: border-box; padding: 0px;"><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">-</span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">Dmaven</span></span><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box; padding: 0px;"><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">.</span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">test</span><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box; padding: 0px;"><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">.</span></span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;"><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">skip</span></span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box; padding: 0px;"><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">=</span></span><span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="kwd" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">true</span></span></code>

maven会报找不到构件的错误。查其原因,是因为这个项目太老了,当时是用maven2构建的,项目中用到的依赖版本也比较老了,而且它们所在的repository已经停用了,因此无法自动下载。解决方法,直接exclusion缺少的依赖即可:

<code class=" hljs xml" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: Arial, Helvetica, sans-serif;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">dependency</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
            </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">groupId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">org.apache.zookeeper</span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">groupId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
            </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">artifactId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">zookeeper</span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">artifactId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
            </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">version</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">3.3.3</span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">version</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
            </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">exclusions</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
                </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">exclusion</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
                    </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">groupId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">com.sun.jmx</span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">groupId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
                    </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">artifactId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">jmxri</span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">artifactId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
                </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">exclusion</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
                </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">exclusion</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
                    </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">groupId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">com.sun.jdmk</span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">groupId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
                    </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">artifactId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">jmxtools</span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">artifactId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
                </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">exclusion</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
                </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">exclusion</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
                    </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">groupId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">javax.jms</span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">groupId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
                    </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">artifactId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">jms</span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">artifactId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
                </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">exclusion</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
            </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">exclusions</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
        </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">dependency</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span></code>

第一次访问控制台时会出现以下配置页面: 
技术分享
第一行指定zookeeper的地址、端口,第二行是超时时间。用户名和密码在这里没有任何用处,无视即可。要注意的是第三行Zookeeper的根目录,这并不是指的部署zookeeper时指定的dataDir,而是一个你自己指定的、与当前管理控制台在同一个机器上的目录,tbSchedule管理控制台会将任务的配置信息(如执行开始时间,调度策略)保存到该目录下,这样下次启动管理控制台时就可以直接从目录中读取配置信息了。

填写完成后点保存,此时上面会出现一行红字,无视之。直接点击管理主页即可进入管理页面: 
技术分享

至此tbSchedule控制台部署完毕。

tbSchedule客户端编写

tbSchedule项目的test/目录下有很多测试类,可以执行

<code class=" hljs " style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: Arial, Helvetica, sans-serif;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background: transparent;"><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">mvn test</span></code>

把测试跑一遍。跑之前要修改项目中schedule.xml文件正确填写zookeeper的连接地址。测试跑通则说明tbSchedule管理控制台和zookeeper都部署无误。

当我们要执行一个job时,需要创建新项目,引入tbschedule依赖,实现指定接口,然后打成jar包,通过

<code class=" hljs avrasm" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: Arial, Helvetica, sans-serif;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background: transparent;"><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">java </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">-</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">jar </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">你的</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">jar</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">名</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box; padding: 0px;"><span class="pun" style="color: rgb(102, 102, 0); box-sizing: border-box; padding: 0px;">.</span><span class="pln" style="color: rgb(0, 0, 0); box-sizing: border-box; padding: 0px;">jar</span></span></code>

启动job。依赖如下:

<code class=" hljs xml" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: Arial, Helvetica, sans-serif;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">groupId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">com.taobao.pamirs.schedule</span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">groupId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
    </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">artifactId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">tbschedule</span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">artifactId</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
</span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">version</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">3.2.16</span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); padding: 0px;"><span class="tag" style="box-sizing: border-box; padding: 0px;">version</span></span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span></span></code>

同时别忘了集成spring。

Main方法代码如下:

<code class=" hljs java" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: Arial, Helvetica, sans-serif;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">public</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">static</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">void</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-title" style="box-sizing: border-box; padding: 0px;"><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">main</span></span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">(</span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">String</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">[]</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> args</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">)</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">throws</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">Exception</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">{</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
        </span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">ApplicationContext</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> ctx </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">=</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">new</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">ClassPathXmlApplicationContext</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">(</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
                </span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"spring-config.xml"</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">);</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">

        </span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">TBScheduleManagerFactory</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> scheduleManagerFactory </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">=</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">new</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">TBScheduleManagerFactory</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">();</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">

        </span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">Properties</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> p </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">=</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">new</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">Properties</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">();</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
        p</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">.</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">put</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">(</span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"zkConnectString"</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">,</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"192.168.3.117:2181"</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">);</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
        p</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">.</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">put</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">(</span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"rootPath"</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">,</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"/home/platform/data"</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">);</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
        p</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">.</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">put</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">(</span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"zkSessionTimeout"</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">,</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"60000"</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">);</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
        p</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">.</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">put</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">(</span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"userName"</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">,</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"ScheduleAdmin"</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">);</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
        p</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">.</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">put</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">(</span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"password"</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">,</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"password"</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">);</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
        p</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">.</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">put</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">(</span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"isCheckParentPath"</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">,</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"true"</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">);</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
        scheduleManagerFactory</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">.</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">setApplicationContext</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">(</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">ctx</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">);</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
        scheduleManagerFactory</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">.</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">init</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">(</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">p</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">);</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
        scheduleManagerFactory</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">.</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">setZkConfig</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">(</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">convert</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">(</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">p</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">));</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">


    </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">}</span></code>

执行这个方法后,你的程序就会向zookeeper发起连接,注册当前机器,请求任务队列,最后根据调度配置执行job。 
job的执行代码需要配置成一个spring bean:

<code class=" hljs applescript" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: Arial, Helvetica, sans-serif;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background: transparent;"><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><bean</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-property" style="box-sizing: border-box; padding: 0px;"><span class="atn" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">id</span></span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">=</span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"testTaskBean"</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-type" style="box-sizing: border-box; padding: 0px;"><span class="atn" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">class</span></span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">=</span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"com.anzhi.schedule.task.TestTaskBean"</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
        </span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"><</span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">property</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-property" style="box-sizing: border-box; padding: 0px;"><span class="atn" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">name</span></span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">=</span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"jdbcTemplate"</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;"><span class="atn" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">ref</span></span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">=</span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"jdbcTemplate"</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">/></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
    </span><span class="tag" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);"></bean></span></code>

这个bean的骨架如下:

<code class=" hljs php" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: Arial, Helvetica, sans-serif;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">public</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-class" style="box-sizing: border-box; padding: 0px;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;"><span class="kwd" style="box-sizing: border-box; padding: 0px;">class</span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-title" style="box-sizing: border-box; color: rgb(102, 0, 102); padding: 0px;"><span class="typ" style="box-sizing: border-box; padding: 0px;">TestTaskBean</span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;"><span class="kwd" style="box-sizing: border-box; padding: 0px;">implements</span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-title" style="box-sizing: border-box; color: rgb(102, 0, 102); padding: 0px;"><span class="typ" style="box-sizing: border-box; padding: 0px;">IScheduleTaskDealSingle</span></span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);"><</span><span class="hljs-title" style="box-sizing: border-box; color: rgb(102, 0, 102); padding: 0px;"><span class="typ" style="box-sizing: border-box; padding: 0px;">PassportModel</span></span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">{</span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
    </span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box; padding: 0px;"><span class="com" style="box-sizing: border-box; padding: 0px;">/**
     * 选择任务. 从DB中读取数据, 将取出的数据返回
     *</span><span class="hljs-phpdoc" style="color: rgb(102, 0, 102); box-sizing: border-box; padding: 0px;"><span class="com" style="color: rgb(136, 0, 0); box-sizing: border-box; padding: 0px;"> @param</span></span><span class="com" style="box-sizing: border-box; padding: 0px;"> taskParameter
     *</span><span class="hljs-phpdoc" style="color: rgb(102, 0, 102); box-sizing: border-box; padding: 0px;"><span class="com" style="color: rgb(136, 0, 0); box-sizing: border-box; padding: 0px;"> @param</span></span><span class="com" style="box-sizing: border-box; padding: 0px;"> ownSign
     *</span><span class="hljs-phpdoc" style="color: rgb(102, 0, 102); box-sizing: border-box; padding: 0px;"><span class="com" style="color: rgb(136, 0, 0); box-sizing: border-box; padding: 0px;"> @param</span></span><span class="com" style="box-sizing: border-box; padding: 0px;"> taskItemNum
     *</span><span class="hljs-phpdoc" style="color: rgb(102, 0, 102); box-sizing: border-box; padding: 0px;"><span class="com" style="color: rgb(136, 0, 0); box-sizing: border-box; padding: 0px;"> @param</span></span><span class="com" style="box-sizing: border-box; padding: 0px;"> taskItemList
     *</span><span class="hljs-phpdoc" style="color: rgb(102, 0, 102); box-sizing: border-box; padding: 0px;"><span class="com" style="color: rgb(136, 0, 0); box-sizing: border-box; padding: 0px;"> @param</span></span><span class="com" style="box-sizing: border-box; padding: 0px;"> eachFetchDataNum
     *</span><span class="hljs-phpdoc" style="color: rgb(102, 0, 102); box-sizing: border-box; padding: 0px;"><span class="com" style="color: rgb(136, 0, 0); box-sizing: border-box; padding: 0px;"> @return</span></span><span class="com" style="box-sizing: border-box; padding: 0px;">
     *</span><span class="hljs-phpdoc" style="color: rgb(102, 0, 102); box-sizing: border-box; padding: 0px;"><span class="com" style="color: rgb(136, 0, 0); box-sizing: border-box; padding: 0px;"> @throws</span></span><span class="com" style="box-sizing: border-box; padding: 0px;"> Exception
     */</span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
    </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">public</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;"><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">List</span></span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);"><</span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">PassportModel</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> selectTasks</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">(</span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">String</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> taskParameter</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">,</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">String</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> ownSign</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">,</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
                                         </span><span class="kwd" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">int</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> taskItemNum</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">,</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;"><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">List</span></span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);"><</span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">TaskItemDefine</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> taskItemList</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">,</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
                                         </span><span class="kwd" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">int</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> eachFetchDataNum</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">)</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="kwd" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">throws</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;"><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">Exception</span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">{</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">

        </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;"><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">List</span></span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);"><</span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">PassportModel</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;"><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">list</span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">=</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">new</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">ArrayList</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);"><</span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">PassportModel</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">>(</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box; padding: 0px;">1</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">);</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
        </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;"><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">list</span></span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">.</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">add</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">(</span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">new</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">PassportModel</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">());</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
        </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">return</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;"><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">list</span></span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">;</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
    </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">}</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">

    </span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box; padding: 0px;"><span class="com" style="box-sizing: border-box; padding: 0px;">/**
     * 向目标表中插入数据
     *</span><span class="hljs-phpdoc" style="color: rgb(102, 0, 102); box-sizing: border-box; padding: 0px;"><span class="com" style="color: rgb(136, 0, 0); box-sizing: border-box; padding: 0px;"> @param</span></span><span class="com" style="box-sizing: border-box; padding: 0px;"> model
     *</span><span class="hljs-phpdoc" style="color: rgb(102, 0, 102); box-sizing: border-box; padding: 0px;"><span class="com" style="color: rgb(136, 0, 0); box-sizing: border-box; padding: 0px;"> @param</span></span><span class="com" style="box-sizing: border-box; padding: 0px;"> ownSign
     *</span><span class="hljs-phpdoc" style="color: rgb(102, 0, 102); box-sizing: border-box; padding: 0px;"><span class="com" style="color: rgb(136, 0, 0); box-sizing: border-box; padding: 0px;"> @return</span></span><span class="com" style="box-sizing: border-box; padding: 0px;">
     *</span><span class="hljs-phpdoc" style="color: rgb(102, 0, 102); box-sizing: border-box; padding: 0px;"><span class="com" style="color: rgb(136, 0, 0); box-sizing: border-box; padding: 0px;"> @throws</span></span><span class="com" style="box-sizing: border-box; padding: 0px;"> Exception
     */</span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
    </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">public</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="kwd" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">boolean</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> execute</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">(</span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">PassportModel</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> model</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">,</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">String</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> ownSign</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">)</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
            </span><span class="kwd" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">throws</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;"><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">Exception</span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">{</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
        </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">try</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">{</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
            </span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box; padding: 0px;">//insertData(model);</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
            </span><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">System</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">.</span><span class="kwd" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 136);">out</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">.</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">println</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">(</span><span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box; padding: 0px;">"执行任务"</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">);</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">

            </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">return</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">true</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">;</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
        </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">}</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">catch</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">(</span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;"><span class="typ" style="box-sizing: border-box; padding: 0px; color: rgb(102, 0, 102);">Exception</span></span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> e</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">)</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">{</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
            e</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">.</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">printStackTrace</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">();</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
            </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">return</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);"> </span><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box; padding: 0px;">false</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">;</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
        </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">}</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
    </span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">}</span><span class="pln" style="box-sizing: border-box; padding: 0px; color: rgb(0, 0, 0);">
</span><span class="pun" style="box-sizing: border-box; padding: 0px; color: rgb(102, 102, 0);">}</span></code>

其中泛型参数Passport是我们自定义的类。

tbSchedule的调用流程为:

  1. 执行selectTasks()方法,该方法返回一个List对象,表示你选择出的任务列表。
  2. 执行execute()方法,tbschedule会遍历你在selectTasks()方法中返回的List,然后对每一个元素都调用execute()方法。

任务调度的配置

进入tbSchedule管理控制台,创建一个新策略: 
技术分享

注意,任务名称格式为创建的任务名$自定义字符串。其中你自定义的字符串会被传递到selectTasks()方法中的ownSign参数中。

任务管理 -> 创建新任务: 
技术分享

这是对单个job的调度配置信息。 
重要参数说明:

  • 任务名称 
    • 就是刚才在配置策略时填写的名称($之前的部分)。
  • 处理模式 
    • SLEEP模式 
      • 当某一个线程任务处理完毕,从任务池中取不到任务的时候,检查其它线程是否处于活动状态。如果是,则自己休眠; 如果其它线程都已经因为没有任务进入休眠,当前线程是最后一个活动线程的时候,就调用业务接口,获取需要处理的任务,放入任务池中, 同时唤醒其它休眠线程开始工作。
    • NOTSLEEP模式 
      • 当一个线程任务处理完毕,从任务池中取不到任务的时候,立即调用业务接口获取需要处理的任务,放入任务池中。
  • 任务项 
    • 一个线程组(会有多个线程)只执行一个任务
    • 一个任务项只能由一个任务处理器执行
    • 任务处理器是一个逻辑性的概念,一个任务处理器只有一个线程组
    • 所以可以把任务划分为1,2,3,4,5,6,7,8, 9, 10一共10个任务碎片,10个任务碎片会被分配到10(刚才在创建调度策略中配置的)个线程组,那么每个线程组对应1个任务碎片,运行时任务项参数又被传递到bean任务类selectTasks方法的List queryCondition参数,例如第1个线程组调用selectTasks方法是queryCondition参数条件为1 ,第2个线程组执行参数条件为2。 我们需要在方法中自己解析这个数值,根据值的不同执行不同部分的任务。因为一个线程组会有多个线程,因此可以实现并行计算

执行job

完成以上工作后,运行编写的job客户端,job即可被调度执行。 
技术分享

淘宝开源项目TbSchedule的部署和使用

举报

相关文章推荐

详解应对平台高并发的分布式调度框架TBSchedule

详解应对平台高并发的分布式调度框架TBSchedule http://geek.csdn.net/news/detail/65738 声明:本文为CSDN原创投稿文章,未经许可...

淘宝开源项目TbSchedule的部署和使用

tbschedule项目其实可以分为两部分: schedule管理控制台。负责控制、监控任务执行状态 实际执行job的客户端机器。 在实际使用时,首先要启动zookeeper, 然后部署tbsched...

精选:深入理解 Docker 内部原理及网络配置

网络绝对是任何系统的核心,对于容器而言也是如此。Docker 作为目前最火的轻量级容器技术,有很多令人称道的功能,如 Docker 的镜像管理。然而,Docker的网络一直以来都比较薄弱,所以我们有必要深入了解Docker的网络知识,以满足更高的网络需求。

淘宝开源项目TbSchedule的部署和使用

tbschedule项目其实可以分为两部分: schedule管理控制台。负责控制、监控任务执行状态实际执行job的客户端程序。 在实际使用时,首先要启动zookeeper, 然后部署tbsche...

钻一钻Tomcat 之 Tomcat项目部署(Ⅵ)

Tomcat调配好了,下面来部署项目。 网上可以找到很多方法,什么静态部署,动态部署,下面总结一下: 二、静态加载   1、直接将web项目文件件拷贝到webapps 目录中     Tom...

eclipse实现JavaWeb项目 增量打包

很多情况下,项目是不允许全量发布的,所以你得把有做修改的文件一个个挑出来,如果有成千上百的文件,你是不是要头大了? 以下方法应该可以让你得到解救!前提是你是用装有svn plugin的eclipse上...

Tomcat部署JSP项目

1.安装jdk 2.配置环境变量 http://jingyan.baidu.com/article/6dad5075d1dc40a123e36ea3.html 3.下载tomcat(绿色版) 4.修改...

使用myeclipse部署项目

很多刚刚接触到web编程的同学还不知道如何使用IDE部署项目,今天就以myeclipse(PHP开发用PHPStorm的多一些)为例做一个介绍。 首先,在myeclipse的左侧区域右键然后Impor...

eclipse构建maven的web项目

使用Eclipse的maven构建一个web项目 1、选择建立Maven Project 选择File -> New -> Other,在New窗口中选择 Maven -> Maven Proj...

Tomcta免安装版配置

一、下载Tomcat  Tomcat可以从http://tomcat.apache.org/网站下载,选择任意版本,在 Binary Distributions 下的zip包既是。 二、配...

Tomcat6虚拟路径的配置

例如Tomcat6安装在D:\Program Files\Tomcat 6.0 1.编辑文件D:\Program Files\Tomcat 6.0\conf\server.xml文件:  ...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)