[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
terracotta对quartz的集群如何实现?  XML
Forum Index -> Terracotta 中文社区
Author Message
lzc_java

neo

Joined: 08/13/2009 18:43:16
Messages: 5
Offline

你好,我希望对quartz集群,但是不想使用数据库,想利用terracotta,但是我不知道该怎么配置?你能给一个例子么?我参考下,谢谢
说明:我已使用terracotta对tomcat、spring、pojo进行过集群,但是唯独没有看懂和学会使用terracotta对quartz的集群
lima

consul
[Avatar]
Joined: 06/22/2009 10:12:31
Messages: 361
Offline

我刚刚把quartz和Terracotta整合的文档翻译了一下,提交到论坛里:
http://forums.terracotta.org/forums/posts/list/0/2426.page#14363

基本上只要把tim-quartz下载下来,把它包含在tc-config.xml文件里,然后修改你原来代码有关Quartz的配置,使用RAMJobStore,就大功告成了。当你在不同机器上执行你的Java程序的时候,他们的任务调度部分就被集群化了。
lzc_java

neo

Joined: 08/13/2009 18:43:16
Messages: 5
Offline

你好,lima,我想把我的一个关于terracotta 与 quartz集群的例子传到论坛里,让你帮我看看是哪里去了问题,为什么关掉其中一个应用程序,另一个可以检测到,但却没有恢复job继续执行?但是没有找到传输附件的地方,现在我将代码分别复制上来,请你帮指正下
这是一个Job类
Code:
package com.test;
 
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
 import org.quartz.Job;
 import org.quartz.JobDataMap;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
 
 public class SimpleJob implements Job {
 	private static final String COUNT = "count";
 	int count = 0;
 
 	public void execute(JobExecutionContext context)
 			throws JobExecutionException {
 
 		JobDataMap data = context.getJobDetail().getJobDataMap();
 		if (data.containsKey(COUNT)) {
 			count = data.getInt(COUNT);
 		} else {
 			count = 0;
 		}
 		count++;
 		data.put(COUNT, count);
 		
 		String fullName = context.getJobDetail().getFullName();
 		
 		System.out.println(getDateTimeString() + "SimpleJob 已执行次数:" + count);
 	}
 
 	public String getDateTimeString() {
 		SimpleDateFormat sdf = new SimpleDateFormat();
 		String format = "yyyy-MM-dd HH:mm:ss";
 		sdf.applyPattern(format);
 		return sdf.format(new Date());
 	}
 }

测试程序如下:
Code:
package com.test;
 
 import org.quartz.CronTrigger;
 import org.quartz.JobDetail;
 import org.quartz.Scheduler;
 import org.quartz.SchedulerFactory;
 import org.quartz.impl.StdSchedulerFactory;
 
 public class Test {
 	public static void main(String args[]) {
 		try {
 			SchedulerFactory schedulerFactory = new StdSchedulerFactory();
 			Scheduler scheduler = schedulerFactory.getScheduler();
 			scheduler.start();
 
 			JobDetail jobDetail = new JobDetail("job1_2", "jGroup1",
 					SimpleJob.class);
 			CronTrigger cronTrigger = new CronTrigger("trigger1_2", "tgroup1",
 					"0/4 * * * * ?");
 
 			if (scheduler.getJobDetail("job1_2", "jGroup1") == null) {
 				System.out.println("创建此Job.....");
 				scheduler.scheduleJob(jobDetail, cronTrigger);
 			} else {
 				System.out.println("未创建此Job.....");
 			}
 			
 			org.quartz.utils.DirtyFlagMap map=null;
 			
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
 	}
 }



tc_config.xml文件如下:
Code:
<?xml version="1.0" encoding="UTF-8"?>
 <con:tc-config xmlns:con="http://www.terracotta.org/config">
 	<servers>
 		<server host="%i" name="localhost">
 			<dso-port>9510</dso-port>
 			<jmx-port>9520</jmx-port>
 			<data>terracotta/server-data</data>
 			<logs>terracotta/server-logs</logs>
 			<statistics>terracotta/cluster-statistics</statistics>
 		</server>
 	</servers>
 	<clients>
 		<modules>
 			<module name="tim-quartz-1.5.1" version="1.2.0-SNAPSHOT" />
 		</modules>
 		<logs>terracotta/client-logs</logs>
 		<statistics>terracotta/client-statistics/%D</statistics>
 	</clients>
 	<application>
 		<dso>
 			<additional-boot-jar-classes>
 				<include>java.util.TimeZone</include>
 				<include>sun.util.calendar.ZoneInfo</include>
 			</additional-boot-jar-classes>
 		</dso>
 	</application>
 </con:tc-config>

我用的集成开发环境是myEclipse,并利用你们提供的eclipse插件,当我启动terracotta服务端后,运行2次测试程序后,发现第二次运行时,的确没有创建job,但是当第一次运行的测试程序终止后,第二次运行的测试测试程序并没有接管并继续执行下去,请你帮忙看看是不是tc_config.xml该加些什么东西?
lzc_java

neo

Joined: 08/13/2009 18:43:16
Messages: 5
Offline

terracotta对quartz的集群到底实现了么?
我看英文论坛里关于对quartz的集群说是还没有解决?
到底能不能啊?
 
Forum Index -> Terracotta 中文社区
Go to:   
Powered by JForum 2.1.7 © JForum Team