We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Scheduling the 10 process at fixed time with one day late

This is the code where i am matching the sql date and time with current date and time and want to do the process in the background in java.For that i have used Cron Scheduler in java.I am attaching the snapshot of the error.Please do help me .

//ScheduleTask.java
package com.demo.model;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/
*
* @author archana agarwal
/
import client.backup_generator.BackupStream;
import client.chunking_module.ChunkingModuleText;
import client.fingerprint_generator.FingerprintGeneratorText;
import java.util.Date;
import java.awt.Toolkit;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import text.server.HashvalueUpdationText;
import text.server.ServerText;


public class ScheduleTask implements Runnable {

Toolkit toolkit;
List filearray = new ArrayList();
Timer timer;
String backup_files;
String email_id;

public void run() {
while(true){
try {
long cumulative=0;
Class.forName(“com.mysql.jdbc.Driver”);
Connection con = DriverManager.getConnection(“jdbc:mysql://localhost:3306/primary_data_text”,“root”, “password”);

String query=“select rr.email_id,fr.reference_user_id,fr.time_requested,fr.Scheduled_On,fr.files from register_repository rr, client_request_repository fr where rr.user_id=fr.user_id”;
Statement st = con.createStatement();
ResultSet rs=st.executeQuery(query);
DateFormat formatter = new SimpleDateFormat(“dd-MMM-yy hh:mm a”);
String date = formatter.format(new java.util.Date());
System.out.println(date.substring(0));
while(rs.next()){
if (date.equals(rs.getString(“Scheduled_On”))) {
System.out.println(rs.getString(“Scheduled_On”));
System.out.println(“matched”);

String client_id=rs.getString(“reference_user_id”);
String[]client=client_id.split(";;");
for(int j=0;j<client.length;j++)
{
int user_id=Integer.parseInt(client[j]);
String sql=" select email_id from register_repository where user_id=?";
try{
PreparedStatement ps =con.prepareStatement(sql);
ps.setInt(1,user_id);
ResultSet rs1 = ps.executeQuery();
while(rs1.next()){
String email_id= rs1.getString(“email_id”);
//filearray1.add(email_id);
//String [] email = filearray1.toArray(new String[filearray1.size()]);

long startTime=System.currentTimeMillis();
//backup_for_files
String backup_for_files=rs.getString(“Files”);
String[] backup_files=backup_for_files.split(";;");
for(int i=j;i<backup_files.length;i++)
{

FingerprintGeneratorText file_dao =new FingerprintGeneratorText();
String hashvalue=file_dao.getFingerprint(backup_files[i]);
String sql2=“select * from file_repository where hashvalue=?”;
try{
PreparedStatement pres = con.prepareStatement(sql2);
pres.setString(1,hashvalue);
ResultSet rs2 = pres.executeQuery();
if(rs2.next())
{
HashvalueUpdationText hs=new HashvalueUpdationText(backup_files[i],email_id);
// filearray.clear();
}else {
filearray.add(backup_files[i].trim());
String [] filesarr = filearray.toArray(new String[filearray.size()]);
// backup_for_files =filesarr;

ChunkingModuleText chkm1 = new ChunkingModuleText(filesarr);
System.out.println(“Running Chunking Module…”);
BackupStream backup_stream = chkm1.doBackup();
System.out.println(“Backup Stream done…!!!”);

ServerText server1 = new ServerText();

server1.setemail_id(email_id);
server1.getemail_id();
server1.writeBackupStream(backup_stream);
long endTime = System.currentTimeMillis( );

cumulative += endTime - startTime;

System.out.println( "Total elapsed time is: " + cumulative );
filearray.clear();
Thread.sleep(1000);
// add 24 hrs to the time and
// write code for scheduling a call
}


} catch (SQLException ex) {
Logger.getLogger(ScheduleTask.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(ScheduleTask.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(ScheduleTask.class.getName()).log(Level.SEVERE, null, ex);
} catch (NullPointerException ex) {
Logger.getLogger(ScheduleTask.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalStateException ex) {
Logger.getLogger(ScheduleTask.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(ScheduleTask.class.getName()).log(Level.SEVERE, null, ex);
}
}

}
} catch (SQLException ex) {
Logger.getLogger(ScheduleTask.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println(“Time’s up!”);
toolkit.beep();
// timer.cancel(); //Not necessary because we call System.exit
//System.exit(0); // Stops the AWT thread (and everything else)
}
} else {
System.out.println(rs.getString(“Scheduled_On”));
System.out.println(“NOT matched”);

}
}
} catch (SQLException ex) {
Logger.getLogger(ScheduleTask.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(ScheduleTask.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

public static void main(String args[]) {
System.out.println(“About to schedule task.”);


// new ScheduleTask();


//System.out.println("Task is starting on … " + now.add(Calendar.DATE, 1));

// + 24 hours
//);


System.out.println(“Task scheduled.”);
}
}

//Cronejobs,java(Main Class)
/
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.demo.model;

/
*
* @author archana agarwal
*/
public class Cronejobs {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
ScheduleTask bjob = new ScheduleTask();
bjob.run();
}
}
Hi Archana,

Thank you for contacting us. It is not really about Aspose APIs. These forums are specific to Aspose APIs. You can Google for appropriate forum and post your query there.