Browse Source

HADOOP-1253. Fix ConcurrentModificationException and NullPointerException in JobControl. Contributed by Johan Oskarson.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@529227 13f79535-47bb-0310-9956-ffa450edef68
Thomas White 18 years ago
parent
commit
c9164d0638

+ 4 - 0
CHANGES.txt

@@ -194,6 +194,10 @@ Trunk (unreleased changes)
     slaves file for stopping datanode.  
     (Michael Bieniosek via tomwhite)
 
+59. HADOOP-1253.  Fix ConcurrentModificationException and 
+    NullPointerException in JobControl.  
+    (Johan Oskarson via tomwhite)
+
 
 Release 0.12.3 - 2007-04-06
 

+ 2 - 1
src/java/org/apache/hadoop/mapred/jobcontrol/Job.java

@@ -243,7 +243,8 @@ public class Job {
 			this.state = Job.FAILED;
 			this.message = StringUtils.stringifyException(ioe);
 			try {
-				running.killJob();
+				if(running != null)
+					running.killJob();
 			} catch (IOException e1) {
 
 			}

+ 15 - 8
src/java/org/apache/hadoop/mapred/jobcontrol/JobControl.java

@@ -19,6 +19,7 @@
 package org.apache.hadoop.mapred.jobcontrol;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Hashtable;
 import java.util.Iterator;
 
@@ -74,10 +75,13 @@ public class JobControl implements Runnable{
 	
 	private static ArrayList toArrayList(Hashtable jobs) {
 		ArrayList retv = new ArrayList();
-		Iterator iter = jobs.values().iterator();
-		while (iter.hasNext()) {
-			retv.add(iter.next());
+		synchronized (jobs) {
+			Iterator iter = jobs.values().iterator();
+			while (iter.hasNext()) {
+				retv.add(iter.next());
+			}
 		}
+		
 		return retv;
 	}
 	
@@ -159,13 +163,16 @@ public class JobControl implements Runnable{
 	}
 	
 	/**
-	 * @param args
+	 * Add a collection of jobs
+	 * 
+	 * @param jobs
 	 */
-	public static void main(String[] args) {
-		// TODO Auto-generated method stub
-
+	public void addJobs(Collection<Job> jobs) {
+		for (Job job : jobs) {
+			addJob(job);
+		}
 	}
-
+	
 	/**
 	 * @return the thread state
 	 */