rafa120
rafa120

Reputation: 21

ERROR org.quartz.core.JobRunShell - Job group1.JobReport threw an unhandled Exception

There is a strange problem when generating the report using QUARTZ scheduler

I can generate a report fine! no problem.

the method (reportsBean) works normally, but there is a problem when passing through quartz

Any idea please?? I don't know what to do anymore :/

13449 [MyScheduler_Worker-1] ERROR org.quartz.core.JobRunShell - Job group1.JobReport threw an unhandled Exception: java.lang.NullPointerException at com.changes.bean.ReportsBean.createPdfCriticalChanges(ReportsBean.java:104) at com.changes.quartz.JobReport.execute(JobReport.java:36) at org.quartz.core.JobRunShell.run(JobRunShell.java:202) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) 13452 [MyScheduler_Worker-1] ERROR org.quartz.core.ErrorLogger - Job (group1.JobReport threw an exception. org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NullPointerException] at org.quartz.core.JobRunShell.run(JobRunShell.java:213) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) Caused by: java.lang.NullPointerException at com.changes.bean.ReportsBean.createPdfCriticalChanges(ReportsBean.java:104) at com.changes.quartz.JobReport.execute(JobReport.java:36) at org.quartz.core.JobRunShell.run(JobRunShell.java:202)

reportsbean

public class JobReport implements Job {


    public void execute(JobExecutionContext context) throws JobExecutionException {


        //BasicConfigurator.configure();
        try {
            ReportsBean reportsBean = new ReportsBean();
            reportsBean.createPdfCriticalChanges();
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy – hh:mm:ss");
            System.out.println("Rodou: " + dateFormat.format( new Date() ));
        } catch (JRException | SQLException e) {
            e.printStackTrace();
        }

    }

}

quartz.properties

org.quartz.scheduler.instanceName = MyScheduler
org.quartz.threadPool.threadCount = 3
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.plugin.jobInitializer.class =org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = com/changes/quartz/quartz-config.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true

web.xml

<!-- Inicio Quartz -->
<servlet>
    <servlet-name>QuartzServlet</servlet-name>
    <servlet-class>com.changes.quartz.servlet.QuartzServlet</servlet-class>
</servlet>
<servlet>
    <servlet-name>QuartzInitializer</servlet-name>
    <servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
    <init-param>
        <param-name>config-file</param-name>
        <param-value>quartz.properties</param-value>
    </init-param>
    <init-param>
        <param-name>shutdown-on-unload</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>start-scheduler-on-load</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>
<!-- Fim Quartz -->

Upvotes: 2

Views: 20723

Answers (6)

Alvaro Rodrigues
Alvaro Rodrigues

Reputation: 1

I fix this problem by creating a Lookup Utils, job was like this :

public class LimpezaColetaDadosPessoaJob implements Job {

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        try {
            this.executar();
        } catch (final BusinessException e) {

        } catch (final Exception e) {
            e.printStackTrace();
        }

    }

    private void executar() throws NamingException {
        final ColetorDadosPessoasIntegracaoService service = LookupUtils
                .lookup(ColetorDadosPessoasIntegracaoService.class);
        service.executarLimpezaDaTabela();
    }

}

Upvotes: 0

user9731810
user9731810

Reputation:

ReportsBean is not able to create an object on this place. If it's a Spring application please use @Autowired annotations to fix this issue:

@Autowired
ReportsBean reportsBean;

Then use call reportsBean.yourMethod();.

Upvotes: 0

munjal007
munjal007

Reputation: 245

I had same issue, I solved by putting time greater than current time in table that stores next_fire_time. then restart the server.

Upvotes: 0

Purushottam
Purushottam

Reputation: 148

it's not throws JobExecutionExceptionnb use @postController and @override method init

Upvotes: 0

rafa120
rafa120

Reputation: 21

at the line 104: String report FacesContext.getCurrentInstance().getExternalContext().getRealPath("/web/reports/criticalcr.jrxml");

Remember: it's working out of quartz.

ReportsBean

public void createPdfCriticalChanges() throws JRException,SQLException {
            System.out.println("generating report...");

            String report = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/web/reports/criticalcr.jrxml");
            JasperReport pathjrxml = JasperCompileManager.compileReport(report);
            //JasperReport pathjrxml = JasperCompileManager.compileReport("web/reports/criticalcr.jrxml"); //Funciona com o inicia Agenda em XML "web/reports/changetracker_criticalcr.jrxml"
            JasperPrint printReport = JasperFillManager.fillReport(pathjrxml, null, conn.getConn());
            JasperExportManager.exportReportToPdfFile(printReport, "/web/reports/changetracker_criticalcr.pdf"); //Funciona com o inicia Agenda em XML "web/reports/criticalcr.pdf"
            System.out.println("report generated!");
    }

Upvotes: 0

mam10eks
mam10eks

Reputation: 1086

The Problem is that you have a NullPointerException in your ReportsBean.

Since the signature of the Quartz execute method is

public void execute(JobExecutionContext context) throws JobExecutionException

Quartz can only deal with JobExecutionException's that will be thrown within this method. But in your case it gets an unexpected NullPointerException.

To solve this Problem you should remove the cause of the NullPointer. From the sourcecode above I couldnt figure out the cause of this exception since it occurs within your ReportsBean.

Certainly your method ReportsBean.createPdfCriticalChanges trys to access an uninitialized member.

Upvotes: 0

Related Questions