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

John Hewson commented on PDFBOX-2882:
-------------------------------------

That's great, it's looking much simpler. You can simplify further by replacing 
freePageCount with freePages.cardinality(). I think there's still room for 
reducing the brittleness of this code though - the close() logic is very 
complex, yet the RandomAccessFile already has the ability the throw an 
IOException in cases of use after close, so we don't need our own logic to do 
this. Simply make the usual calls to RandomAccessFile and let it throw an 
exception if it's been closed.

Note that there's no need to clear freePages or inMemoryPages in the close() 
method - memory management in Java is controlled by ownership (i.e. RAII), not 
by manual memory management. This has come up before on the mailing list - the 
purpose of close() is to close native system resources, not to release memory. 
(For a clear example of this from Sun, look at the close() method of 
ByteArrayOutputStream - it's empty) This is good, because it means that we 
don't need to do any isClosed bookkeeping for the in-memory pages in 
ScratchFile, we can simply rely on RandomAccessFile to throw IOException if it 
is closed, as normal.

Finally, I still see a lot of volatile variables, I assume that they are no 
longer needed?

> Improve performance when using scratch file
> -------------------------------------------
>
>                 Key: PDFBOX-2882
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2882
>             Project: PDFBox
>          Issue Type: Improvement
>          Components: Parsing
>    Affects Versions: 2.0.0
>            Reporter: Timo Boehme
>            Assignee: Timo Boehme
>            Priority: Minor
>         Attachments: ScratchFile.java, ScratchFileBuffer.java
>
>
> The current scratch file implementation uses many direct I/O calls which 
> slows down parsing compared with in-memory scratch buffer considerably.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to