Execution Time exceed Quartz Scheduler Trigger every minute - java

I have questions on how to use the scheduler properly.
I'm running a scheduler that trigger a job that sends list of emails at 10:00 am on working days.
The scheduler will trigger the job every 1 minute. However, the execution time for sending an email will take around 5 seconds.
Therefore, if I have 20 emails to send out for a day, it will take 20x5sec = 100 sec.
The scheduler will trigger after 1 minute, before the 20 emails being sent out completely.
Therefore, some emails will be left unsent.
Please kindly advise me on how do I send out the email completely before the next trigger time ?
Below is my sample code.
//CalendarReminder.java
// Job 1 & Group 1
JobDetail job = new JobDetail();
job.setName("Job1");
job.setJobClass(SendEmailJob.class);
job.setGroup("group1");
//example of adding an excluded day of the week - This excludes sundays from job
//firing schedule
WeeklyCalendar weeklyOff = new WeeklyCalendar();
weeklyOff.setDayExcluded(Calendar.SUNDAY, true);
// Trigger 1
//configure the scheduler time
SimpleTrigger trigger = new SimpleTrigger();
trigger.setStartTime(new Date(System.currentTimeMillis() + 1000));
trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
trigger.setRepeatInterval(60000); // Trigger every 1 min
trigger.setGroup("group1");
trigger.setName("trigger1");
try{
//schedule the job
scheduler = new StdSchedulerFactory().getScheduler();
scheduler.addCalendar("weeklyOff", weeklyOff, false, true);
scheduler.start();
scheduler.scheduleJob(job, trigger);
}catch(Exception ex){
}
-----------------------------------------------------------------------------
//SendEmailJob.java
try {
//getting database connection to MySQL server
dbCon = DriverManager. getConnection(dbURL, username, password);
//getting PreparedStatment to execute query
stmt = dbCon.prepareStatement(query);
//Resultset returned by query
rs = stmt.executeQuery(query);
while(rs.next()){
Str_Company = rs.getString("erscheduledemail.company");
Str_Dept = rs.getString("erscheduledemail.dept");
Str_EventType = rs.getString("erscheduledemail.eventtype");
Str_OneTimeDate = rs.getString("erscheduledemail.onetimedate");
Str_TimeSend = rs.getString("erscheduledemail.timesend");
Str_EmailFrom = rs.getString("erscheduledemail.emailfrom");
Str_EmailTo = rs.getString("erscheduledemail.emailto");
Str_EmailCCTo = rs.getString("erscheduledemail.emailccto");
Str_EmailSubject = rs.getString("erscheduledemail.emailsubject");
Str_EmailMessage = rs.getString("erscheduledemail.emailmessage");
Str_DeliveryStatus = rs.getString("erscheduledemail.deliverystatus");
Str_ActiveStatus = rs.getString("erscheduledemail.activestatus");
// Retrieve Scheduled Records Date yyyy-mm-dd & Time hh:mm:ss
Int_Year = Integer.parseInt(Str_OneTimeDate.substring(0, 4));
Int_Month = Integer.parseInt(Str_OneTimeDate.substring(5, 7));
Int_Day = Integer.parseInt(Str_OneTimeDate.substring(8,10));
Int_Hour = Integer.parseInt(Str_TimeSend.substring(0, 2));
Int_Min = Integer.parseInt(Str_TimeSend.substring(3, 5));
Int_Sec = Integer.parseInt(Str_TimeSend.substring(6, 8));
// Retrieve Computer System Date & Time
Calendar SysCalen = Calendar.getInstance();
int sys_calYear = SysCalen.get(Calendar.YEAR);
int sys_calMonth = SysCalen.get(Calendar.MONTH) + 1;
int sys_calDay = SysCalen.get(Calendar.DAY_OF_MONTH);
int sys_calHour = SysCalen.get(Calendar.HOUR_OF_DAY);
int sys_calMinute = SysCalen.get(Calendar.MINUTE);
int sys_calSecond = SysCalen.get(Calendar.SECOND);
// If the time match at 10:00 am
if(sys_calYear == Int_Year && sys_calMonth == Int_Month && sys_calDay == Int_Day &&
sys_calHour == Int_Hour && sys_calMinute == Int_Min /*&& sys_calSecond == Int_Sec*/){
System.out.println( " The time now" + String.valueOf(sys_calHour) + ":" +
String.valueOf(sys_calMinute) + ":" + String.valueOf(sys_calSecond));
System.out.println( " company: " +Str_Company);
SendingEmail(Str_EmailFrom,Str_EmailTo,Str_EmailCCTo, Str_EmailSubject, Str_
EmailMessage);
// Update deliverystatus to Yes and ActiveStatus to No
stm = dbCon.createStatement();
sql = "UPDATE erscheduledemail SET deliverystatus = 'Y', activestatus = 'N' "
+
"WHERE company = '"+Str_Company+"' and dept = '"+Str_Dept+"' and onetimedate =
'"+Str_OneTimeDate+"' and eventtype = '"+Str_EventType+"' ";
//Execute INSERT SQL Statement
stm.executeUpdate(sql) ;
}
}
dbCon.close();
} catch (SQLException ex) {
//System.out.println("SQL Exception thrown :" + ex);
System.out.println("SQL Exception thrown :" + ex);
}
Thanks & Regards,
Goshen

Related

DoNotForward Graph Api Event With Java

I have an application I am working on where a user will make an reservation for an office. Once the user makes it they are sent a calendar event via graph api so their Calendar reflects their reservation. I am trying to use the DoNotForward Boolean type to send in the singleValueExtendedProperties setting but nothing has worked.
Please Only answer using Java as the language. Thank you
**Note that I am sending the event and receiving it without any trouble until I try to add the DoNotForward. Below is a portion of the code that represents the Graph API Event.
Questions:
Has anyone configured an Event with the DoNoForward Option?
Can you provide me some guidance on what I am doing wrong?
Event event = new Event();
ItemBody eventBody = new ItemBody();
eventBody.contentType = BodyType.HTML;
eventBody.content = doc.html();
event.body = eventBody;
event.subject = "MyWorkSpot Reservation (" + environmentName + ") : " + buildingName + " Floor: " + floorName + " Seat: " + seatCode + " Time: " + reservationTime;
event.showAs = FreeBusyStatus.FREE;
event.isReminderOn = false;
event.reminderMinutesBeforeStart = 0;
event.isAllDay = true;
DateTimeTimeZone start = new DateTimeTimeZone();
start.dateTime = formattedResAllDayStartDate + "T00:00:00";
start.timeZone = "Eastern Standard Time";
event.start = start;
DateTimeTimeZone end = new DateTimeTimeZone();
end.dateTime = nextDay + "T00:00:00";
end.timeZone = "Eastern Standard Time";
event.end = end;
LinkedList<Attendee> attendeesList = new LinkedList<Attendee>();
Attendee attendees = new Attendee();
EmailAddress emailAddressEvent = new EmailAddress();
emailAddressEvent.address = recipientEmailAddress;
attendees.emailAddress = emailAddressEvent;
attendees.type = AttendeeType.REQUIRED;
attendeesList.add(attendees);
event.attendees = attendeesList;
SingleValueLegacyExtendedPropertyCollectionResponse singleValColRes = new SingleValueLegacyExtendedPropertyCollectionResponse();
SingleValueLegacyExtendedProperty singleValProp = new SingleValueLegacyExtendedProperty();
singleValProp.id = "Boolean {00020329-0000-0000-C000-000000000046} Name DoNotForward";
singleValProp.value = "true";
singleValProp.oDataType = "Boolean";
singleValColRes.value.add(0, singleValProp);
event.singleValueExtendedProperties = new SingleValueLegacyExtendedPropertyCollectionPage(singleValColRes, null);

Updating database table is failing using update clause in hibernate

am trying to update a batch of columns in a table called customer . it works when i update two columns when hard coded the data.my aim is to fetch data from another table will updating the other. please here. it's not throwing any exception but just the code is not running . Thanks in advance
Session session = HibernateUtil.getSessionFactory().openSession();
customerdata.stream().forEach((row) -> {
session.beginTransaction();
// record data loggingg of customer import data transaction
String sql = "UPDATE Customer SET first_name = :first_name ,second_name = :second_name,"
+ "other_names = :other_name,gender = :gender,"
+ "date_opened = :date_opened,date_approved = :date_approved,branch_code = :branch_code,"
+ "national_id_number = :national_id_number,crb_number = :crb_number,"
+ "passport_number = :passport_number,passport_expiry_date = :passport_expiry_date,"
+ "voters_number = :voters_number,student_id_number = :student_id_number,"
+ "employer_id_number = :employer_id_number,finance_card_number = :finance_card_number,"
+ "driving_permit_number = :driving_permit_number,nssf_number = :nssf_number,tin_number = :tin_number,"
+ "police_id_number = :police_id_number,updf_number = :updf_number,"
+ "mobile = :mobile,telephone1 = :telephone1,telephone2 = :telephone2,"
+ "email = :email ,is_salaried = :is_salaried,plot_number = :plot_number,postal_address = :postal_address,"
+ "street = :street,account_operating_mode = :account_operating_mode,"
+ "primary_account_type = :primary_account_type,"
+ "address_type = :address_type,address_description = :address_description,dob_given = :dob_given,"
+ "date_of_birth = :date_of_birth, client_type = :client_type, country_of_origin = :country_of_origin,"
+ "city_of_origin = :city_of_origin,city_description = :city_description, employment_type = :employment_type,"
+ "introducer_details_available = :introducer_details_available,literacy_level = :literacy_level,"
+ "literacy_description = :literacy_description,marital_status = :marital_status,"
+ "marital_status_description = :marital_status_description,"
+ "nationality = :nationality,number_of_dependants = :number_of_dependants,residence = :residence,"
+ "residence_type = :residence_type ,resident_state = :resident_state,type_of_id = :type_of_id,"
+ "client_status = :client_status ,date_closed = :date_closed WHERE rim = :rim";
Query query = session.createQuery(sql);
query.setParameter("fname", row[2].toString());
query.setParameter("second_name", row[3].toString());
query.setParameter("other_name", row[4].toString());
query.setParameter("gender", row[5].toString());
query.setParameter("date_opened", (Date) row[6]);
query.setParameter("date_approved", (Date) row[7]);
query.setParameter("branch_code", row[8].toString());
query.setParameter("national_id_number", Integer.parseInt(row[9].toString()));
query.setParameter("crb_number", row[10].toString());
query.setParameter("passport_number", row[11].toString());
query.setParameter("passport_expiry_date", (Date) row[12]);
query.setParameter("voters_number", row[13].toString());
query.setParameter("student_id_number", row[14].toString());
query.setParameter("employer_id_number", row[15].toString());
query.setParameter("finance_card_number", row[16].toString());
query.setParameter("driving_permit_number", row[17].toString());
query.setParameter("nssf_number", row[18].toString());
query.setParameter("tin_number", row[19].toString());
query.setParameter("police_id_number", row[20].toString());
query.setParameter("updf_number", row[21].toString());
query.setParameter("mobile", row[22].toString());
query.setParameter("telephone1", row[23].toString());
query.setParameter("telephone2", row[24].toString());
query.setParameter("email", row[25].toString());
query.setParameter("is_salaried", (Boolean) row[26]);
query.setParameter("plot_number", row[27].toString());
query.setParameter("postal_address", Integer.parseInt(row[28].toString()));
query.setParameter("street", row[29].toString());
query.setParameter("account_operating_mode", Integer.parseInt(row[30].toString()));
query.setParameter("primary_account_type", Integer.parseInt(row[31].toString()));
query.setParameter("address_type", row[32].toString());
query.setParameter("address_description", row[33].toString());
query.setParameter("dob_given", (Boolean) row[34]);
query.setParameter("date_of_birth", (Date) row[35]);
query.setParameter("client_type", row[36].toString());
query.setParameter("country_of_origin", row[37].toString());
query.setParameter("city_of_origin", row[38].toString());
query.setParameter("city_description", row[39].toString());
query.setParameter("employment_type", row[40].toString());
query.setParameter("introducer_details_available", row[41].toString());
query.setParameter("literacy_level", row[42].toString());
query.setParameter("literacy_description", row[43].toString());
query.setParameter("marital_status", row[44].toString());
query.setParameter("marital_status_description", row[45].toString());
query.setParameter("nationality", row[46].toString());
query.setParameter("number_of_dependants", Integer.parseInt(row[47].toString()));
query.setParameter("residence", row[48].toString());
query.setParameter("residence_type", row[49].toString());
query.setParameter("resident_state", row[50].toString());
query.setParameter("type_of_id", Integer.parseInt(row[51].toString()));
query.setParameter("client_status", row[52].toString());
query.setParameter("date_closed", (Date) row[53]);
//setting rim data
query.setParameter("rim",row[1].toString());
query.executeUpdate();
session.getTransaction().commit();
System.err.println(xx++ + "RIM LOOPED:" + row[1].toString());
});
try {
session.close();
System.out.println("Update customer ends. . . . . . . . . . .");
} catch (NullPointerException nullPointer) {
System.out.println("updateing data log data property ::<updateEntireContent()>: Customer session object is closed.Exception handled. . .>>" + nullPointer);
}

Cron Job Failure on GAE using java with automatic scaling

I am trying to use cron job for executing some work once a day. I am using automatic scaling. Using cron job i am sending emails once a day. I have 2 conditions:
Whenever i set time once a day for example every day 18:00 then cron job run successfully but its only executing 3, 4 lines of CronJob implementation class.
In logger I am getting only 4 lines are executing like this:-
whenever i set time as every 2 minutes or every 5 minutes then cron job run successfully and cron job implementation class executed successfully means its send email successfully.
Why is the first condition not sending email?
Is there may be app is at that time idle and that's why it's not executing?
Any help?
Cron.xml :-
<?xml version="1.0" encoding="UTF-8"?>
<cron>
<url>/slick_erp/cronCustomerService</url>
<description>Implemented for due services of customer.</description>
<schedule>every day 11:30</schedule>
</cron>
</cronentries>
Web.xml:-
<servlet>
<servlet-name>CustomerServiceCronJobImpl</servlet-name>
<servlet-class>com.slicktechnologies.server.cronjobimpl.CustomerServiceCronJobImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CustomerServiceCronJobImpl</servlet-name>
<url-pattern>/slick_erp/cronCustomerService</url-pattern>
</servlet-mapping>
My cronjob implementation class :-
public class CustomerServiceCronJobImpl extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = -6268357776825855510L;
private SimpleDateFormat fmt = new SimpleDateFormat("dd-MMM-yyyy");
private SimpleDateFormat fmt1 = new SimpleDateFormat("dd/MM/yyyy");
Logger logger = Logger.getLogger("NameOfYourLogger");
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
servicecontactlist();
}
private void servicecontactlist() {
fmt.setTimeZone(TimeZone.getTimeZone("IST"));
fmt1.setTimeZone(TimeZone.getTimeZone("IST"));
Email cronEmail = new Email();
Date today=DateUtility.getDateWithTimeZone("IST", new Date());
/**
* Adding 1 day extra to date
*/
logger.log(Level.SEVERE,"Date Before Adding One Day"+today);
DateFormat dateFormat=new SimpleDateFormat("dd/MM/yyyy");
Calendar cal=Calendar.getInstance();
cal.setTime(today);
cal.add(Calendar.DATE, 0);
Date dateForFilter=null;
try {
dateForFilter=dateFormat.parse(dateFormat.format(cal.getTime()));
cal.set(Calendar.HOUR_OF_DAY,23);
cal.set(Calendar.MINUTE,59);
cal.set(Calendar.SECOND,59);
cal.set(Calendar.MILLISECOND,999);
dateForFilter=cal.getTime();
} catch (ParseException e) {
e.printStackTrace();
}
logger.log(Level.SEVERE,"Date After Adding One Date"+dateForFilter);
/*************************************End*********************************/
try{
logger.log(Level.SEVERE,"In service ContactList");
logger.log(Level.SEVERE,"Date After Adding One Date=="+dateForFilter);
logger.log(Level.SEVERE," 1 ");
/********************************Adding status in the list ***********************/
logger.log(Level.SEVERE," 2 ");
ArrayList<String> obj = new ArrayList<String>();
obj.add("Scheduled");
obj.add("Pending");
obj.add("Rescheduled");
logger.log(Level.SEVERE," 3 ");
/******************************Converting todayDate to String format*****************/
logger.log(Level.SEVERE," 4 ");
Date todaysDate = new Date();
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
logger.log(Level.SEVERE," 5 ");
String todayDateString = df.format(todaysDate);
logger.log(Level.SEVERE," 6 ");
System.out.println("String in dd/MM/yyyy format is: " + todayDateString);
logger.log(Level.SEVERE," 7 ");
/********************************Adding Companies in the list ***********************/
logger.log(Level.SEVERE," 8 ");
List<Company> compEntity = ofy().load().type(Company.class).list();
logger.log(Level.SEVERE," 9 ");
if(compEntity.size()>0){
logger.log(Level.SEVERE,"If compEntity size > 0");
logger.log(Level.SEVERE,"Size of compEntity"+compEntity.size());
for(int i=0;i<compEntity.size();i++){
Company c=compEntity.get(i);
logger.log(Level.SEVERE,"In the for loop");
logger.log(Level.SEVERE,"Company Name="+c);
logger.log(Level.SEVERE,"The value of i is:" +i);
logger.log(Level.SEVERE,"Date After Adding One Date"+dateForFilter);
/********************************Checking prosname & prosconfig for each company ***********************/
ProcessName prosName = ofy().load().type(ProcessName.class).filter("processName","CronJob").filter("status",true).filter("companyId", compEntity.get(i).getCompanyId()).first().now();
ProcessConfiguration prosconfig = ofy().load().type(ProcessConfiguration.class).filter("processList.processName", "CronJob").filter("processList.processType", "ServiceDailyMail").filter("processList.status",true).filter("companyId", compEntity.get(i).getCompanyId()).first().now();
logger.log(Level.SEVERE,"after 3 filters for ProcessConfigurations");
System.out.println("after 3 filters for ProcessConfigurations");
if(prosName!=null){
logger.log(Level.SEVERE,"In the prossName");
if(prosconfig!=null){
logger.log(Level.SEVERE,"In the ProsConfifg !=null ");
/********************************Reading services from Service entity ***********************/
List<Service> serEntity = ofy().load().type(Service.class).filter("companyId",compEntity.get(i).getCompanyId()).filter("serviceDate <=",dateForFilter).filter("status IN",obj).list();
logger.log(Level.SEVERE,"Today date Is:"+dateForFilter);
logger.log(Level.SEVERE,"service entity size:"+serEntity.size());
// email id is added to emailList
ArrayList<String> toEmailList=new ArrayList<String>();
toEmailList.add(compEntity.get(i).getPocEmail());
String mailTitl = "Services Due As On Date";
if(serEntity.size()>0){
ArrayList<String> tbl_header = new ArrayList<String>();
tbl_header.add("Branch");
tbl_header.add("Customer Id");
tbl_header.add("Customer Name");
tbl_header.add("Customer Contact No");
tbl_header.add("Crontact Id");
tbl_header.add("Service Id");
tbl_header.add("Service Date");
tbl_header.add("Service Engineer");
tbl_header.add("Product Name");
tbl_header.add("Status");
tbl_header.add("Ageing");
/********************************Sorting table with Branch & Service Date ***********************/
Comparator<Service> serviceDateComparator2 = new Comparator<Service>() {
public int compare(Service s1, Service s2) {
Date date1 = s1.getServiceDate();
Date date2 = s2.getServiceDate();
//ascending order
return date1.compareTo(date2);
}
};
Collections.sort(serEntity, serviceDateComparator2);
Comparator<Service> serviceDateComparator = new Comparator<Service>() {
public int compare(Service s1, Service s2) {
String branch1 = s1.getBranch();
String branch2 = s2.getBranch();
//ascending order
return branch1.compareTo(branch2);
}
};
Collections.sort(serEntity, serviceDateComparator);
/********************************Getting serviceEntity data and adding in the tbl1 List ***********************/
ArrayList<String> tbl1=new ArrayList<String>();
for(int j=0;j<serEntity.size();j++){
tbl1.add(serEntity.get(j).getBranch()+"");
tbl1.add(serEntity.get(j).getPersonInfo().getCount()+"");
tbl1.add(serEntity.get(j).getPersonInfo().getFullName()+"");
tbl1.add(serEntity.get(j).getPersonInfo().getCellNumber()+"");
tbl1.add(serEntity.get(j).getContractCount()+"");
tbl1.add(serEntity.get(j).getCount()+"");
tbl1.add(fmt.format(serEntity.get(j).getServiceDate()) +"");
/**************** for getting ageing for each service******/
String StringServiceDate = fmt1.format(serEntity.get(j).getServiceDate());
// String StringServiceDate = df.format(serviceDate);
Date d1 = null;
Date d2 = null;
d1 = df.parse(StringServiceDate);
d2 = df.parse(todayDateString);
long diff = d2.getTime() - d1.getTime();
long diffDays = diff / (24 * 60 * 60 * 1000);
System.out.println("Ageing:"+diffDays);
logger.log(Level.SEVERE,"Ageing:"+diffDays);
tbl1.add(serEntity.get(j).getEmployee()+"");
tbl1.add(serEntity.get(j).getProduct().getProductName()+"");
tbl1.add(serEntity.get(j).getStatus()+"");
tbl1.add(diffDays +"");
}
logger.log(Level.SEVERE,"In the ProsConfig !=null 3 ");
/********************************Calling cronsendEmail Method ***********************/
// Email e=new Email();
try {
System.out.println("Before send mail method");
logger.log(Level.SEVERE,"Before send method call to send mail ");
cronEmail.cronSendEmail(toEmailList, "Services Due As On Date"+" "+ todayDateString, mailTitl +" "+ todayDateString, c, tbl_header, tbl1, null, null, null, null);
logger.log(Level.SEVERE,"After send mail method ");
//+" "+
} catch (IOException e1) {
logger.log(Level.SEVERE,"In the catch block ");
e1.printStackTrace();
}
}
else{ // else block for if(serviceEntity.size()>0){
System.out.println("Sorry no services found for this company");
logger.log(Level.SEVERE,"Sorry no services found for this company");
//
mailTitl = "No Services Found Due";
cronEmail.cronSendEmail(toEmailList, "Services Due As On Date"+" "+ todayDateString, mailTitl , c, null, null, null, null, null, null);
}
}
else{ //else block for prosconfig
logger.log(Level.SEVERE,"ProcessConfiguration is null");
System.out.println("ProcessConfiguration is null");
}
}else{ //else block for pross!=null
logger.log(Level.SEVERE,"Cron job status is Inactive");
System.out.println("Cron job status is Inactive");
}
} //end of for loop
}
else{ //else block for if(compEntity.size()>0)
logger.log(Level.SEVERE,"No Company found from cron job completed");
System.out.println("No Company found from cron job completed");
}
}catch(Exception e2){
e2.printStackTrace();
}
}
}

Java EWS findappointments dates acting weird, either returns to much or nothing

I'm not sure how the start and end date work with the whole find appointments. I am getting all the rooms for a public group, then getting the rooms for the group, then getting the appointments within a date range.
But the ranges act weird, I know there are appointments on 12-19 to 12-16, but if I set the start date range to 2013-10-10 and the end date to 2013-12-28, I get nothing.
If I set the end date to 2014-01-28, I get tons of stuff that is in the range previously mentioned. Why is that?
ExchangeService service = new ExchangeService();
ExchangeCredentials credentials = new WebCredentials( "username", "pw");
service.setCredentials( credentials );
service.setUrl( new URI("my mail url") );
Folder inbox = Folder.bind(service, WellKnownFolderName.Inbox);
System.out.println("messages: " + inbox.getTotalCount());
CalendarFolder cf = CalendarFolder.bind(service, WellKnownFolderName.Calendar);
//Get all new appts?
java.text.SimpleDateFormat formatter= new java.text.SimpleDateFormat("YYYY-mm-dd");
Date startDate1 = formatter.parse("2013-11-25");
Date endDate1 = formatter.parse("2014-01-28 ");
EmailAddressCollection myRoomLists = service.getRoomLists();
for (EmailAddress item : myRoomLists)
{
System.out.println("Room Email========"+ item.toString());
NameResolutionCollection nameResolutions = service.resolveName(
item.getName(),
ResolveNameSearchLocation.DirectoryOnly,
true);
for (NameResolution nameResolution : nameResolutions)
{
ExpandGroupResults groupResults;
//System.out.println(nameResolution.getMailbox().getAddress());
try {
groupResults = service.expandGroup(nameResolution.getMailbox().getAddress());
} catch (microsoft.exchange.webservices.data.ServiceResponseException e){
groupResults=null;
System.out.println("NO INFO FOR "+nameResolution.getMailbox().getAddress());
}
if (groupResults!=null){
for (EmailAddress member : groupResults.getMembers())
{
if (member.getAddress().indexOf("rm.Cary")>-1){
System.out.println(member.getName() + " <" + member.getAddress() + ">");
FolderId folderid = new FolderId(WellKnownFolderName.Calendar, new Mailbox(member.getAddress()));
try {
FindItemsResults<Appointment> aps = service.findAppointments(folderid, new CalendarView(startDate1,endDate1));
for (Item items : aps.getItems())
{
Appointment appt = (Appointment)items;
System.out.println("SUBJECT===== " + appt.getSubject());
System.out.println("Location======== " + appt.getLocation());
System.out.println("Start Time========" + appt.getStart());
System.out.println("End Time========"+appt.getEnd());
System.out.println("Email Address========"+ appt.getOrganizer().getAddress());
System.out.println("Last Modified Time========"+appt.getLastModifiedTime());
System.out.println("Start time========"+appt.getStart());
System.out.println("End Time========"+appt.getEnd());
System.out.println("Is recurring========"+appt.getIsRecurring());
System.out.println("Duration========"+appt.getDuration().toString());
System.out.println("Organizer========"+appt.getOrganizer());
System.out.println("Required Attendees========"+appt.getRequiredAttendees().getCount());
System.out.println("Optional Attendees========"+appt.getOptionalAttendees().getCount());
System.out.println("");
}
} catch (microsoft.exchange.webservices.data.ServiceResponseException e){
System.out.println(e.getMessage());
}
}
}
}
}
}
System.out.println("End");
Change it to:
java.text.SimpleDateFormat formatter= new java.text.SimpleDateFormat("yyyy-MM-dd");

Program getting executed indefinetly after comparing with system time

Explanation -
StartTime is being fetched from a table (EX- 2014-07-25 12:00:00)
Startwork() does the insert function
do {
long time = startTime.getTime() + (((59 * 60) + 59) * 1000);
Date endTime = new Date(time);
System.out.println("INFO: Calling startWork(" + startTime + "," + endTime + ")");
startWork(startTime, endTime);
startTime = new Date(startTime.getTime() + (60 * 60 * 1000));
systemHour = new Date(new Date().getYear(), new Date().getMonth(), new Date().getDate(), new Date().getHours(), 0, 0);
String stringToUpdateLastProcessedTime = "update meter_thread set last_processed_time='" + sdf.format(startTime) + "' where name='Gateway Park Occupancy' ";
mysqlStatement.executeUpdate(stringToUpdateLastProcessedTime);
}
while (startTime.getTime() != systemHour.getTime());
System.out.println("INFO: Switching to live mode");
Thread.sleep(1000 * 55 * 60);
The problem I am encountering is that, the program is getting executed for future dates if the starttime fetched from the table is (ex -2014-07-25 12:00:00) and the current system time is (ex-2014-07-25 12:20:00) instead of switching to live mode.
Please help in where I am going wrong.
I would change:
while(startTime.getTime() != systemHour.getTime())
For
while(startTime.getTime() > systemHour.getTime())
Is rather improbable (almost impossible) that your loop check will match to the millisecond the startTime instant.

Categories

Resources