Pessoal estou usando o Java 2D pra gerar uma imagem, porém a carga dessa imagem está muito lenta (algo em torno de 15 ~20s), mas apenas na 1ª solicitação, as outras requisições são rápidas.
O código é esse:
public byte[] gerarImagem(String codigoGerado) throws IOException {
int width = 165 , height = 75;
BufferedImage buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = buffer.createGraphics();
g.setColor(Color.WHITE);
g.fillRect( 0, 0, width, height );
Font font = new Font("Courier New", Font.BOLD, 40);
AttributedString as = new AttributedString(codigoGerado);
as.addAttribute(TextAttribute.FONT, font);
as.addAttribute(TextAttribute.FOREGROUND, Color.BLACK);
g.drawString(as.getIterator(), 10 , 50); //A DEMORA ESTÁ NESSA LINHA AQUI
g.setColor(Color.WHITE);
..............................
Alguém pode me dizer porque isso acontece e como faço pra aumentar a performance desse código?