com.sp2p.task.JobInTimeTask.java Source code

Java tutorial

Introduction

Here is the source code for com.sp2p.task.JobInTimeTask.java

Source

/*
 * cron4j - A pure Java cron-like scheduler
 * 
 * Copyright (C) 2007-2010 Carlo Pelliccia (www.sauronsoftware.it)
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version
 * 2.1, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License 2.1 for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License version 2.1 along with this program.
 * If not, see <http://www.gnu.org/licenses/>.
 */
package com.sp2p.task;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.web.context.ContextLoader;

import com.sp2p.service.AssignmentDebtService;
import com.sp2p.service.BorrowService;
import com.sp2p.service.admin.BorrowManageService;

/**
 * This task counts from 1 to 30.
 */
public class JobInTimeTask extends QuartzJobBean {

    private static Log log = LogFactory.getLog(JobInTimeTask.class);
    private static boolean isRunning = false;

    private JobTaskService jobTaskService;
    private BorrowService borrowService;
    private AssignmentDebtService assignmentDebtService;
    private long sleepTime;

    @Override
    protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException {

        long start = System.currentTimeMillis();
        //
        JobTaskService jobTaskService = (JobTaskService) getBean("jobTaskService");
        //
        BorrowService borrowService = (BorrowService) getBean("borrowService");
        //?
        AssignmentDebtService assignmentDebtService = (AssignmentDebtService) getBean("assignmentDebtService");

        BorrowManageService borrowManageService = (BorrowManageService) getBean("borrowManageService");

        try {
            if (!isRunning) {
                log.info("");
                jobTaskService.autoBidNew();
                log.info("?");
                log.info("??");
                jobTaskService.sendtoTemple();
                log.info("???");
                //            jobTaskService.publistBorrow();?

                log.info("?");
                borrowManageService.updateTimerSend();
                log.info("??");

                log.info("??");
                borrowService.refreshBorrowTime();
                log.info("???");

                //            log.info("??");  ????.
                //            jobTaskService.sendShortMessge();
                //            log.info("???");

                log.info("??");
                assignmentDebtService.checkDueDebt();
                log.info("???");

                isRunning = false;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }
        log.info(" : " + (System.currentTimeMillis() - start) + "" + "SystemMemery:freeMemory"
                + Runtime.getRuntime().freeMemory() + "-------maxMemory" + Runtime.getRuntime().maxMemory()
                + "-------totalMemory" + Runtime.getRuntime().totalMemory());
    }

    public boolean canBePaused() {

        return true;
    }

    public boolean canBeStopped() {
        return true;
    }

    public boolean supportsCompletenessTracking() {
        return true;
    }

    public boolean supportsStatusTracking() {
        return true;
    }

    private Object getBean(String beanName) {
        return ContextLoader.getCurrentWebApplicationContext().getBean(beanName);
    }

    public JobTaskService getJobTaskService() {
        return jobTaskService;
    }

    public void setJobTaskService(JobTaskService jobTaskService) {
        this.jobTaskService = jobTaskService;
    }

    public BorrowService getBorrowService() {
        return borrowService;
    }

    public void setBorrowService(BorrowService borrowService) {
        this.borrowService = borrowService;
    }

    public AssignmentDebtService getAssignmentDebtService() {
        return assignmentDebtService;
    }

    public void setAssignmentDebtService(AssignmentDebtService assignmentDebtService) {
        this.assignmentDebtService = assignmentDebtService;
    }

    public long getSleepTime() {
        return sleepTime;
    }

    public void setSleepTime(long sleepTime) {
        this.sleepTime = sleepTime;
    }
}