diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index 68564b69ec..3f85a9b381 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -311,6 +311,8 @@ Release 2.9.0 - UNRELEASED IMPROVEMENTS + MAPREDUCE-6431. JobClient should be an AutoClosable (haibochen via rkanter) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestJobClient.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestJobClient.java index b18b531abc..bf37b03b61 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestJobClient.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestJobClient.java @@ -87,4 +87,14 @@ public void testGetStagingAreaDir() throws IOException, InterruptedException { client.getClusterHandle().getStagingAreaDir().toString() .equals(client.getStagingAreaDir().toString())); } + + /** + * Asks the compiler to check if JobClient is AutoClosable. + */ + @Test(timeout = 10000) + public void testAutoClosable() throws IOException { + Configuration conf = new Configuration(); + try (JobClient jobClient = new JobClient(conf)) { + } + } } diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java index cf123c7b4e..baa622111f 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java @@ -137,7 +137,7 @@ */ @InterfaceAudience.Public @InterfaceStability.Stable -public class JobClient extends CLI { +public class JobClient extends CLI implements AutoCloseable { @InterfaceAudience.Private public static final String MAPREDUCE_CLIENT_RETRY_POLICY_ENABLED_KEY = @@ -499,6 +499,7 @@ public JobClient(InetSocketAddress jobTrackAddr, /** * Close the JobClient. */ + @Override public synchronized void close() throws IOException { cluster.close(); }