0

I am using BufferedOutputstream write method to write to a file. But it is taking ages to complete. I have same code running on AIX OS and its working just fine, but on RHEL 7.6 its not working as required. Java version is 1.6

Code:

    File localFile = new File(localdir,infile.getName());

    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(localFile));

    byte[] b = new byte[8192];
    int n = 0;


    while(( n = smbIn.read( b )) > 0 ) {

        out.write( b, 0, n );
    }

    out.flush();
    out.close();

    smbIn.close();
    out.close();

    return localFile;
Sarshad
  • 29
  • 4
  • did you try to debug and see, where does it get stuck? you could also take the heapdump in jvisualvm and share the stacktrace? – Jatin Nov 20 '19 at 10:56
  • It does not get stuck actually. Logs show the write function working : INFO: In while/opt/dataloading/data/statisticalbss/4G_Updated_Region-Sheet-15-11-2019.xlsx to [B@3e1c436b 0 8192 – Sarshad Nov 20 '19 at 10:58
  • Most likely, it is `smbIn.read` is what is slow. Use `strace -f -T` to debug. – Lorinczy Zsigmond Nov 20 '19 at 11:44
  • 1
    Unless the incoming reads return very small chunks (in which case you have identified the actual problem), the `BufferedOutputStream` adds nothing to the performance, as you are already using a sufficiently sized buffer array on your own. – Holger Jan 13 '20 at 15:27

0 Answers0