title: Howto make image generation scalable on Java?
body: <p>I'm trying to improve performance of captcha image rendering in web app running on Linux. Looking at what is currently used, I found that the bottleneck is in the usage of Java2D and specifically Graphics2D class.</p>
  
  <p>The problem is not much with the speed of execution, but more with scalability. Basically it doesn't scale. Drawing of captcha images in 1 thread or 2 threads doesn't make any improvement in terms of execution time.</p>
  
  <p>As an example, you can have a look at following class which is creating background for captcha images. The problem appears on calls to Graphics2D::setColor() and Graphics2D::drawLine():</p>
  
  <p><a href="http://www.docjar.com/html/api/com/octo/captcha/component/image/backgroundgenerator/FunkyBackgroundGenerator.java.html" rel="nofollow">http://www.docjar.com/html/api/com/octo/captcha/component/image/backgroundgenerator/FunkyBackgroundGenerator.java.html</a></p>
  
  <p>After some googling and I found topic which says that Java2d is not particularly well with multi-threading (sorry, not allowed to give more than one link :) but, you can easily find that topic if google for 'java2d multithreading', it will be the first result)</p>
  
  <p>I believe that there must be some library which provides drawing capabilities withtout using Java2d, but failed to find it :( Or Java2d, probably, can be switched to some mode, which doesn't block on access to graphics object (btw, headless mode doesn't help). </p>
  
  <p>I will appreciate any suggestions. Beforehand, thanks for answers.</p>