[ 
https://issues.apache.org/jira/browse/HADOOP-16282?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16832717#comment-16832717
 ] 

Giovanni Matteo Fumarola commented on HADOOP-16282:
---------------------------------------------------

Thanks [~daryn] for your feedback.
I think we should fix the potential leaks (they are even present in the 
original code) instead of reverting the patch.

e.g.
{code:java}
InputStream in = null;
OutputStream out =null;
try {
  in = Files.newInputStream(src.toPath());
  out = dstFS.create(dst);
  IOUtils.copyBytes(in, out, conf);
} catch (IOException e) {
  IOUtils.closeStream( out );
  IOUtils.closeStream( in );
  throw e;
}
{code}
The variable in and out can leak resources/handles. I am pretty aware of this 
problem since I hit it in production.

We should add the finally clause:
{code:java}
try{
} catch (){
} finally {
  in.close();
  out.close();
}
{code}
or use a Try-with-resources clause:
{code:java}
 try InputStream in = Files.newInputStream(src.toPath()); etc..){{code}

> Avoid FileStream to improve performance
> ---------------------------------------
>
>                 Key: HADOOP-16282
>                 URL: https://issues.apache.org/jira/browse/HADOOP-16282
>             Project: Hadoop Common
>          Issue Type: Improvement
>            Reporter: Ayush Saxena
>            Assignee: Ayush Saxena
>            Priority: Major
>             Fix For: 3.3.0
>
>         Attachments: HADOOP-16282-01.patch, HADOOP-16282-02.patch
>
>
> The FileInputStream and FileOutputStream classes contains a finalizer method 
> which will cause garbage collection pauses. See 
> [JDK-8080225|https://bugs.openjdk.java.net/browse/JDK-8080225] for details.
> The FileReader and FileWriter constructors instantiate FileInputStream and 
> FileOutputStream, again causing garbage collection issues while finalizer 
> methods are called.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to