Hi all,
I'm working with a web application ( tomcat ) which receives certain parameters and generates an image Graphics2D ( 200x100 px ) dynamically (ie , the text shown in the image depends on the parameters ) , then turns and finally BufferedImage makes PNG and returned to the client. 1,000 request currently processed per minute.
To generate the image use Graphics2D ( AWT ) and methods java.awt.Graphics2D.drawString("text " , 5, 5)
. This works fine, except that the generated image shows the very pixelated text.
So I switched to SWT. With SWT solved the problem of pixelated text, it takes some time to generate the image (5ms). But now a new problem related threads:
In tomcat, currentThreadsBusy value grows indefinitely, and many are looking at the threads in WAITING state:
"http -8080 -13" - Thread t @ 57
java.lang.Thread.State : WAITING
at java.lang.Object.wait ( Native Method)
- Waiting on < 6575c693 > (a org.eclipse.swt.widgets.RunnableLock )
at java.lang.Object.wait ( Object.java : 503)
at org.eclipse.swt.widgets.Synchronizer.syncExec ( Unknown Source )
at org.eclipse.swt.widgets.Display.syncExec ( Unknown Source )
at com .... imgen.domain.model.graphic.impl.swt.SWTPlotter.execRunnable ( SWTPlotter.java : 56 )
com ..... at imgen.domain.model.graphic.impl.swt.SWTPlotter.drawFlightImage ( SWTPlotter.java : 81)
com ..... at imgen.domain.model.graphic.impl.DrawServiceImpl.drawFlightImage ( DrawServiceImpl.java : 43)
com ..... at imgen.domain.model.templates.t1.FlightTemplate.drawImage ( FlightTemplate.java : 138)
at com ..... imgen.domain.mo
This is partly solved by the "Display.getCurrent().Dispose()", but from other problems that arise with "Widget is disposed" or "Invalid thread access".
The question is:
You should use SWT for concurrently generating 1,000 images per minute in headless mode ?
Or SWT is not designed for that?
That I can evaluate alternatives ?
Thank you very much for everything.
public class SWTPlotter {
// ...
private BufferedImage execRunnable ( SWTRunnable runnable ) throws DrawImageException {
Display.getDefault().SyncExec(runnable);
BufferedImage img = runnable.getImg();
}
}
public class DrawFlightRunnable
implements SWTRunnable {
@ Override
public void run () {
Image image = new Image ( Display.findDisplay ( Thread.currentThread ( ) ) , IMAGE_WIDTH , IMAGE_HEIGHT ) ;
GC gc = new GC (image) ;
gc.setAntialias ( SWT.ON ) ;
gc.setInterpolation ( SWT.HIGH ) ;
gc.drawText ( this.headerText , this.headerConfig.getX ( ) this.headerConfig.getY ());
this.img = ImageUtil.swt2awt ( image.getImageData ( ) ) ;
gc.dispose ();
image.dispose ();
/ / - Failed to execute runnable ( org.eclipse.swt.SWTException : Widget is disposed
/ / Display.getCurrent (). Dispose () ;
}