title: How can I reliably stop a tomcat thread in a spring+pdfbox application?
body: <p>I have tomcat threads being stuck indefinitely (until tomcat is restarted). My application is built in with spring and the last debug message shows me a call to this method:  </p>
  
  <pre><code>public byte[] getPageAsImageByteArray(byte[] pdfFileData, double scale) {
      PDFRenderer renderer = null;
      try (PDDocument doc = PDDocument.load(pdfFileData)) {
  
          renderer = new PDFRenderer(doc);
          BufferedImage img = renderer.renderImage(0, (float) scale);
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          ImageIO.write(img, "png", baos);
          return baos.toByteArray();
  
      } catch (Exception e) {
          log.error("Exception when rendering page using pdfbox", e);
          throw new RuntimeException(e);
      }
  }
  </code></pre>
  
  <p>This call never returns.</p>
  
  <p>Is there a way for me to rewrite this method to reliably exit after a set timeout?</p>