Changeset 11509


Ignore:
Timestamp:
2006-03-28T11:40:28+12:00 (18 years ago)
Author:
shaoqun
Message:

synchronize the job_queues in run method

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/WGet.java

    r9646 r11509  
    107107    }
    108108
    109 
    110109    /** This method is called to delete a certain job from the queue.
    111110     * This job may be pending, complete or even in progress. However
     
    116115     */
    117116    public void deleteDownloadJob(DownloadJob delete_me) {
     117       
    118118    if (delete_me == job) {
    119119        // While this seems wasteful its only for the briefest moment.
     
    263263    public void run() {
    264264    while(true) {
     265         
    265266        // If there are jobs job_queue and we have more room.
    266267        if(job_queue.size() > 0) {
    267268        int index = 0;
    268269        while(job_queue.size() > 0 && index < job_queue.size()) {
    269             // Get the first job that isn't stopped.
    270             job = (DownloadJob) job_queue.get(index);
    271             if(job.getState() == DownloadJob.RUNNING) {
    272             DebugStream.println("DownloadJob " + job.toString() + " Begun.");
    273             // A lock to prevent us deleting this job while its being
     270            // Get the first job that isn't stopped.       
     271            synchronized(job_queue){
     272            job = (DownloadJob) job_queue.get(index);
     273            if(job.getState() == DownloadJob.RUNNING) {
     274                DebugStream.println("DownloadJob " + job.toString() + " Begun.");
     275                // A lock to prevent us deleting this job while its being
    274276            // run, unless you want things to go really wrong.
    275             busy = true;
    276             if(simple) {
    277                 job.callWGet();
     277                busy = true;
     278                if(simple) {
     279                job.callWGet();
     280                }
     281                else {
     282                job.callWGetNative();
     283                }
     284                busy = false;
     285                DebugStream.println("DownloadJob " + job.toString() + " complete.");
     286                // And if the user has requested that complete jobs
     287                // be removed, then remove it from the list.
     288                //deleteDownloadJob(job);
     289                job = null;
    278290            }
    279             else {
    280                 job.callWGetNative();
    281             }
    282             busy = false;
    283             DebugStream.println("DownloadJob " + job.toString() + " complete.");
    284             // And if the user has requested that complete jobs
    285                 // be removed, then remove it from the list.
    286             //deleteDownloadJob(job);
    287             job = null;
     291            index++;
    288292            }
    289             index++;
    290293        }
    291294        }
     
    303306        }
    304307        }
     308       
    305309    } // End While.
    306310    }
Note: See TracChangeset for help on using the changeset viewer.