2004-04-16 07:44:42 UTC
This is my web app:
My servlet is using Quartz Scheduler to periodically send sms content to subscribers. I use,
-MySQL = to store the content and subscribers' phone number
-Quartz scheduler = to do scheduling for delivery of contents
-Log4J = to log all delivery of contents
The problem: My servlet sends the content twice to a subscriber. It suppose to just send once to each subscriber.
Quartz Config:
-Using RAMJobStore
-Using DefaultScheduler with default quartz.properties
No. of jobs: 6
Delivery time: every Wed and Thur (4 jobs) and daily (2 jobs)
MySQL URL connection: jdbc:mysql://178.547.22.345/best_cms?user=best_root&password=pass&autoReconnect=true&useUnicode=true&characterEncoding=ISO-8859-1
So far I’ve done some investigation and it seems that,
-When the scheduler is triggered, the app will start to send a content to the listed subscribers. Say 1000 subscribers subscribe to the service, then my app will delivery ONE content to all the subscribers each.
-However, the app seems to be sending two contents instead.
-I've tested the app in my dev server, and it works well (with the same test data as in production server). But, when I port over to the prod server, TWO contents are sent to one subscriber.
I’ve done triple check on my SQL statements, (even putting the word DISTINCT in), but to no avail.
My dev server specs:
OS: Windows XP
Tomcat 5.0
MySQL 4.0.17
My prod server specs:
OS: RedHat Linux
Tomcat 4.0.3
MySQL 4.0.18
Please help.
Here's the code.
>>ContentScheduler.java
public class ContentScheduler extends HttpServlet {
private Logger log = Logger.getLogger(ContentScheduler.class);
private SchedulerFactory sf = new org.quartz.impl.StdSchedulerFactory();
//private SystemAlert systemAlert = new SystemAlert();
//Initialize method for servlet
public void init(ServletConfig config) throws ServletException {
super.init(config);
//To store the time of deliveries
String scheduleTime1 = "";
String scheduleTime2 = "";
String scheduleTime3 = "";
String scheduleTime4 = "";
String scheduleTime5 = "";
String scheduleTime6 = "";
String scheduleTime7 = "";
String scheduleTime8 = "";
//Get the log4j properties file location from web.xml
//<context-param>
String props = config.getServletContext().getInitParameter("props");
//To pass the log4j file location parameter to this instances
PropertyFileLocation.setFileLocation(props);
//Get the time of deliveries from web.xml <ini-param>
scheduleTime1 = config.getInitParameter("schedule1");
scheduleTime2 = config.getInitParameter("schedule2");
scheduleTime3 = config.getInitParameter("schedule3");
scheduleTime4 = config.getInitParameter("schedule4");
scheduleTime5 = config.getInitParameter("schedule5");
scheduleTime6 = config.getInitParameter("schedule6");
scheduleTime7 = config.getInitParameter("schedule7");
scheduleTime8 = config.getInitParameter("schedule8");
if (props == null
|| props.length() == 0
|| !(new File(props)).isFile()) {
System.err.println(
"ERROR: Cannot read the log4j configuration file. "
+ "Please check the path of the config init param in web.xml");
throw new ServletException();
}
System.err.println(
ContentScheduler.class.getName()
+ " is using properties file: "
+ props);
//Configure the log4j
PropertyConfigurator.configure(props);
//Starting the scheduling process
try {
Scheduler schedule = sf.getScheduler();
//Run the delivery of monophonic ringtones
JobDetail job =
new JobDetail(
"MonoRingtoneDelivery",
"Group1",
MonoRingtoneDelivery.class);
CronTrigger cTrigger =
new CronTrigger(
"TriggerMonoRingtoneDelivery",
"Group1",
"MonoRingtoneDelivery",
"Group1",
scheduleTime1);
Date ft = schedule.scheduleJob(job, cTrigger);
//run the delivery of polyphonic ringtones
job =
new JobDetail(
"PolyRingtoneDelivery",
"Group2",
PolyRingtoneDelivery.class);
cTrigger =
new CronTrigger(
"TriggerPolyRingtoneDelivery",
"Group2",
"PolyRingtoneDelivery",
"Group2",
scheduleTime2);
ft = schedule.scheduleJob(job, cTrigger);
//Run the delivery of picture messages
job =
new JobDetail(
"PictureMessageDelivery",
"Group3",
PictureMessageDelivery.class);
cTrigger =
new CronTrigger(
"TriggerPictureMessageDelivery",
"Group3",
"PictureMessageDelivery",
"Group3",
scheduleTime3);
ft = schedule.scheduleJob(job, cTrigger);
//Run the delivery of screensaver
job =
new JobDetail(
"ScreensaverDelivery",
"Group4",
ScreensaverDelivery.class);
cTrigger =
new CronTrigger(
"TriggerScreensaverDelivery",
"Group4",
"ScreensaverDelivery",
"Group4",
scheduleTime4);
ft = schedule.scheduleJob(job, cTrigger);
//Run the delivery of operator logo
job =
new JobDetail(
"OperatorLogoDelivery",
"Group5",
OperatorLogoDelivery.class);
cTrigger =
new CronTrigger(
"OperatorLogoDelivery",
"Group5",
"OperatorLogoDelivery",
"Group5",
scheduleTime5);
ft = schedule.scheduleJob(job, cTrigger);
//Run the delivery of wallpaper
job =
new JobDetail(
"WallpaperDelivery",
"Group6",
WallpaperDelivery.class);
cTrigger =
new CronTrigger(
"WallpaperDelivery",
"Group6",
"WallpaperDelivery",
"Group6",
scheduleTime6);
ft = schedule.scheduleJob(job, cTrigger);
//Run the delivery of quote service
job =
new JobDetail(
"QuoteDelivery",
"Group7",
QuoteDelivery.class);
cTrigger =
new CronTrigger(
"QuoteDelivery",
"Group7",
"QuoteDelivery",
"Group7",
scheduleTime7);
ft = schedule.scheduleJob(job, cTrigger);
//Run the delivery of fun service
job =
new JobDetail(
"FunDelivery",
"Group8",
FunDelivery.class);
cTrigger =
new CronTrigger(
"FunDelivery",
"Group8",
"FunDelivery",
"Group8",
scheduleTime8);
ft = schedule.scheduleJob(job, cTrigger);
//Start the scheduler
schedule.start();
} catch (Exception e) {
log.info("Class: " + ContentScheduler.class.getName());
log.warn("System message: Error in ContentScheduler");
log.warn("ERROR message: " + e);
//Alert the system admin
//systemAlert.sendAlert(ContentScheduler.class.getName());
}
}
public void destroy() {
try {
//This is to shutdown the scheduler when Tomcat is shutdown
Scheduler schedule = sf.getScheduler();
schedule.shutdown(true);
} catch (Exception se) {
log.info("Class: " + ContentScheduler.class.getName());
log.warn("System message: Content Scheduler shutdown error");
log.warn("ERROR message: " + se);
//Alert the system admin
//systemAlert.sendAlert(ContentScheduler.class.getName());
}
}
>>MonoRingtoneDelivery.java
package com.tt.cds.sub;
//Packages for Quartz scheduler
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class MonoRingtoneDelivery implements Job {
//To store the content id for monophonic ringtone
private int contentNumId = 1;
private int phoneTypeId = 1;
private int languageId = 1;
private String tableName="ringtones";
private SubContentDelivery deliverInfo = new SubContentDelivery();
//Method to execute the sendContent method once trigger by the job scheduler
public void execute(JobExecutionContext context)
throws JobExecutionException {
//Deliver the content using the object from class SubContentDelivery
deliverInfo.sendContent(contentNumId, phoneTypeId, languageId, tableName);
}
}
Mel