1

そのため、私のプログラムの詳細をできるだけ一般的に説明すると同時に、一般的な要点を理解しようとします。JobManager と JobWorkers という 2 つの重要なオブジェクトがあります。JobWorker には、完了するまで一定の間隔で実行するタスクがあります。ジョブが開始されることはないため、ジョブが完了したときに何が起こるかは無視します。JobManager のタイマーはオフに設定されていますが、JobWorker タイマーは開始されていません。以下は、状況を理解するのに役立つ疑似コードです。

public class JobWorker
{
    private String jobName;
    private Timer timer;
    private Calendar startTime;

    public JobWorker(String jobName, Calendar startTime, otherFields)
    {
        this.jobName = jobName;
        this.startTime = startTime;
        this.timer = new Timer("EmailJob" + jobName + "-timer");
        //set other fields
    }

    public void start()
    {
        timer.schedule(new TimerTask(){

            public void run()
            {
                //Do stuff - this is where nothing is happening
            }

        }, 0, 60000);
    }

    //Equals method and other stuff
}

public class JobManager
{
    private List<JobWorker> activeWorkers = new ArrayList<JobWorker>();
    private List<JobWorker> pausedWorkers = new ArrayList<JobWorker>();

    private Timer timer;

    public JobManager()
    {
        //loads workers from database

        timer = new Timer("JobManager-timer");

        loadJobs();

        timer.schedule(new TimerTask(){

            public void run()
            {
                //I see this statement every minute as expected
                logger.info("EmailJobManager timer run started.");

                for(JobWorker worker : pausedWorkers)
                {
                    Calendar c = new GregorianCalendar();

                    //I can see worker.getStartTime() in client gui so I know that they have already passed
                    if(c.compareTo(worker.getStartTime()) > 0)
                    {
                        //Never see these log statements
                        logger.info("Memory Address in manager timer loop 2 for " + worker.getEmailJobName() + " ({})", worker.toString());

                        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy - HH:mm");

                        logger.info("Comparing current time ({}) to JobWorker " + worker.getJobName() + " start time ({})", sdf.format(c.getTime()), sdf.format(worker.getStartDate()));

                        activeWorkers.add(worker);
                        pausedWorkers.remove(worker);
                        worker.start();
                    }
                }
            }

        }, 0, 60000);
    }

    public void addWorker(necessary fields)
    {
        //Create JobWorker newWorker = new JobWorker(jobName, blah blah)
        pausedWorkers.add(newWorker);
    }   

    /**
     * Checks to see if any jobs were not completed as expected due to hardware error. Recreates the EmailJob and EmailJobWorker responsible.
     */
    private void loadJobs()
    {
        String SQL = "SELECT * FROM email_jobs";

        List<Map<String, Object>> rows = jt.queryForList(SQL);

        for(Map<String, Object> row : rows)
        {
            JobWorker worker = new JobWorker(stuff it needs from SQL);

            //I see these debug statements
            logger.info("Worker " + worker.getJobName() + " has been added to pausedWorkers list with memory address ({})", worker.toString());
            pausedWorkers.add(worker);

            logger.info("Job " + jobName + " loaded sucessfully.");
        }
}

JobWorker メモリ アドレス (基本的に Object.toString) を出力して、それらのディープ/シャロー コピーに異常があるかどうかを確認するために、さらにデバッグ ステートメントを追加します。何か案は?

編集:さて、何が起こっているのか完全に途方に暮れています。これが完全なクラスです。

http://ideone.com/hR7et

そこには敏感なものは何もないので心配はいりません。

これが私が持っているログ出力です:

2012-04-17 16:34:18,548 INFO [http-bio-8081-exec-97] c.c.e.EmailJobWorker [EmailJobWorker.java:98] EmailJobWorker test was created sucessfully. (batchSize, timeInterval, currentId, startTime) (1, 5, 1, 04/17/12 - 15:15)
2012-04-17 16:34:18,552 INFO [http-bio-8081-exec-97] c.c.e.EmailJobManager [EmailJobManager.java:297] Worker test has been added to pausedWorkers list with memory address (EmailJobWorker@7e7df7d)
2012-04-17 16:34:18,552 INFO [http-bio-8081-exec-97] c.c.e.EmailJobManager [EmailJobManager.java:301] EmailJob test loaded sucessfully.
2012-04-17 16:34:18,557 INFO [http-bio-8081-exec-97] c.c.e.EmailJobWorker [EmailJobWorker.java:98] EmailJobWorker test2 was created sucessfully. (batchSize, timeInterval, currentId, startTime) (1, 5, 1, 04/17/12 - 15:15)
2012-04-17 16:34:18,558 INFO [http-bio-8081-exec-97] c.c.e.EmailJobManager [EmailJobManager.java:297] Worker test2 has been added to pausedWorkers list with memory address (EmailJobWorker@349be26c)
2012-04-17 16:34:18,558 INFO [http-bio-8081-exec-97] c.c.e.EmailJobManager [EmailJobManager.java:301] EmailJob test2 loaded sucessfully.
2012-04-17 16:34:18,558 INFO [http-bio-8081-exec-97] c.c.e.EmailJobManager [EmailJobManager.java:117] EmailJobManager timer started sucesfully. (sleepTime) (1)
2012-04-17 16:34:18,559 INFO [EmailJobManager] c.c.e.EmailJobManager [EmailJobManager.java:74] EmailJobManager timer run started.
2012-04-17 16:34:18,561 INFO [EmailJobManager] c.c.e.EmailJobManager [EmailJobManager.java:85] Size of pausedWorkers: 2
2012-04-17 16:34:18,561 INFO [EmailJobManager] c.c.e.EmailJobManager [EmailJobManager.java:89] Memory Address in manager timer loop 2 for test (EmailJobWorker@7e7df7d)
2012-04-17 16:34:19,501 INFO [EmailJobManager] c.c.e.EmailJobManager [EmailJobManager.java:75] EmailJobManager timer run started.
2012-04-17 16:34:31,984 INFO [EmailJobManager] c.c.e.EmailJobManager [EmailJobManager.java:75] EmailJobManager timer run started.
2012-04-17 16:34:34,562 INFO [EmailJobManager] c.c.e.EmailJobManager [EmailJobManager.java:75] EmailJobManager timer run started.
2012-04-17 16:35:04,840 INFO [EmailJobManager] c.c.e.EmailJobManager [EmailJobManager.java:75] EmailJobManager timer run started.
2012-04-17 16:35:19,501 INFO [EmailJobManager] c.c.e.EmailJobManager [EmailJobManager.java:75] EmailJobManager timer run started.
2012-04-17 16:35:31,984 INFO [EmailJobManager] c.c.e.EmailJobManager [EmailJobManager.java:75] EmailJobManager timer run started.
2012-04-17 16:35:34,562 INFO [EmailJobManager] c.c.e.EmailJobManager [EmailJobManager.java:75] EmailJobManager timer run started.
2012-04-17 16:36:04,840 INFO [EmailJobManager] c.c.e.EmailJobManager 

ご覧のとおり、EmailJobManager は 1 回しか作成されず、JobWorkers のタイマーがオフになることはありませんが、タイマーは 1 分ごとにオフになっているわけではありません。

4

2 に答える 2

2

JobManager のタイマーはオフに設定されていますが、JobWorker タイマーは開始されていません。

お電話JobWorker.startですか?何が起こっているかを確認できるように、さらにコードを含める必要があります。これらのrunメソッドを実行しない理由はありません: http://ideone.com/uEer3

一過性はシリアル化にのみ関連します。

于 2012-04-17T20:06:19.400 に答える
0

そのため、timertasks の run メソッドでエラーが発生しました。これらは匿名であるため、エラーによってメイン メソッドが中断され、黙って失敗しました。

于 2012-04-18T18:10:21.990 に答える