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

Tilman Hausherr commented on PDFBOX-3080:
-----------------------------------------

If I've understood your latest change correctly, you'd doing this:
{quote}
When a thread invokes a synchronized method, it automatically acquires the 
intrinsic lock for that method's object and releases it when the method returns
{quote}
I.e. the synchronised method and the synchronized(this) code never run in 
parallel.

I did a successful test this morning with a change similar to yours but I'll 
retest this one. And I wonder whether we should replace the HashMap with a 
concurrent one.

Btw your patch file is still in the wrong format. Patch files I produce don't 
have an e-mail address, they start like this:
{code}
# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: .....\PDFBox 
reactor\fontbox\src\main\java\org\apache\fontbox\ttf
# This patch can be applied using context Tools: Patch action on respective 
folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: TrueTypeFont.java
--- TrueTypeFont.java Base (BASE)
+++ TrueTypeFont.java Locally Modified (Based On LOCAL)
....
{code}


> TrueTypeFont synchronization
> ----------------------------
>
>                 Key: PDFBOX-3080
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3080
>             Project: PDFBox
>          Issue Type: Improvement
>          Components: FontBox
>    Affects Versions: 2.0.0
>         Environment: Debian, java version "1.8.0_60"
> Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
> Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
>            Reporter: ccouturi
>            Priority: Minor
>         Attachments: 0001-PDFBOX-3080-excessive-synchronization.patch
>
>
> The use case is rasterize pdf to png.
> On high load, a lot of threads are blocked in the 
> TrueTypeFont.getHorizontalMetrics() or getHorinzontalHeader() methods.
> Jstack snippet: 
> {code}
> Thread 21999: (state = BLOCKED)
>  - org.apache.fontbox.ttf.TrueTypeFont.getHorizontalMetrics() @bci=6, 
> line=231 (Compiled frame)
>  - org.apache.fontbox.ttf.TrueTypeFont.getAdvanceWidth(int) @bci=1, line=439 
> (Compiled frame)
>  - org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.getWidthFromFont(int) 
> @bci=11, line=324 (Compiled frame)
>  - 
> org.apache.pdfbox.rendering.PageDrawer.drawGlyph2D(org.apache.pdfbox.rendering.Glyph2D,
>  org.apache.pdfbox.pdmodel.font.PDFont, int, org.apache.pdfbox.util.Vector, 
> java.awt.geom.AffineTransform)
>  @bci=39, line=350 (Compiled frame)
>  - 
> org.apache.pdfbox.rendering.PageDrawer.showFontGlyph(org.apache.pdfbox.util.Matrix,
>  org.apache.pdfbox.pdmodel.font.PDFont, int, java.lang.String, 
> org.apache.pdfbox.util.Vector) @bci=34, line=32
> 5 (Compiled frame)
>  - 
> org.apache.pdfbox.contentstream.PDFStreamEngine.showGlyph(org.apache.pdfbox.util.Matrix,
>  org.apache.pdfbox.pdmodel.font.PDFont, int, java.lang.String, 
> org.apache.pdfbox.util.Vector) @bci=32, li
> ne=728 (Compiled frame)
>  - org.apache.pdfbox.contentstream.PDFStreamEngine.showText(byte[]) @bci=240, 
> line=685 (Compiled frame)
>  - org.apache.pdfbox.contentstream.PDFStreamEngine.showTextString(byte[]) 
> @bci=2, line=553 (Compiled frame)
>  - 
> org.apache.pdfbox.contentstream.operator.text.ShowText.process(org.apache.pdfbox.contentstream.operator.Operator,
>  java.util.List) @bci=45, line=50 (Compiled frame)
>  - 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(org.apache.pdfbox.contentstream.operator.Operator,
>  java.util.List) @bci=35, line=799 (Compiled frame)
>  - 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(org.apache.pdfbox.contentstream.PDContentStream)
>  @bci=69, line=461 (Compiled frame)
>  - 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(org.apache.pdfbox.contentstream.PDContentStream)
>  @bci=63, line=438 (Compiled frame)
>  - 
> org.apache.pdfbox.contentstream.PDFStreamEngine.showForm(org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject)
>  @bci=19, line=178 (Interpreted frame)
>  - 
> org.apache.pdfbox.contentstream.operator.graphics.DrawObject.process(org.apache.pdfbox.contentstream.operator.Operator,
>  java.util.List) @bci=162, line=70 (Interpreted frame)
>  - 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(org.apache.pdfbox.contentstream.operator.Operator,
>  java.util.List) @bci=35, line=799 (Compiled frame)
>  - 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(org.apache.pdfbox.contentstream.PDContentStream)
>  @bci=69, line=461 (Compiled frame)
>  - 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(org.apache.pdfbox.contentstream.PDContentStream)
>  @bci=63, line=438 (Compiled frame)
>  - 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(org.apache.pdfbox.pdmodel.PDPage)
>  @bci=19, line=149 (Interpreted frame)
>  - org.apache.pdfbox.rendering.PageDrawer.drawPage(java.awt.Graphics, 
> org.apache.pdfbox.pdmodel.common.PDRectangle) @bci=93, line=180 (Interpreted 
> frame)
>  - 
> org.apache.pdfbox.rendering.PDFRenderer.renderPage(org.apache.pdfbox.pdmodel.PDPage,
>  java.awt.Graphics2D, int, int, float, float) @bci=160, line=208 (Interpreted 
> frame)
>  - org.apache.pdfbox.rendering.PDFRenderer.renderImage(int, float, 
> org.apache.pdfbox.rendering.ImageType) @bci=166, line=139 (Interpreted frame)
>  - org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(int, float, 
> org.apache.pdfbox.rendering.ImageType) @bci=7, line=94 (Interpreted frame)
> [...]
> {code}
> These methods are synchronized. (I think because of initialization block.)
> When I change from:
> {code:title=actual|borderStyle=solid}
> public synchronized HorizontalHeaderTable getHorizontalHeader() throws 
> IOException {
>     HorizontalHeaderTable horizontalHeader = 
> (HorizontalHeaderTable)tables.get( HorizontalHeaderTable.TAG );
>     if (horizontalHeader != null && !horizontalHeader.getInitialized()) {
>         readTable(horizontalHeader);
>     }
>     return horizontalHeader;
>  }
> {code}
> to:
> {code:title=patch|borderStyle=solid}
> public HorizontalHeaderTable getHorizontalHeader() throws IOException {
>     HorizontalHeaderTable horizontalHeader = (HorizontalHeaderTable) 
> tables.get(HorizontalHeaderTable.TAG);
>     if (horizontalHeader != null && !horizontalHeader.getInitialized()) {
>         synchronized (this) {
>             if (!horizontalHeader.getInitialized()) {
>                 readTable(horizontalHeader);
>             }
>         }
>      }
>      return horizontalHeader;
>  }
> {code}
> the lock disappears.     



--
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