Discussions

EJB programming & troubleshooting: Is there any problem in using java.awt classes from a EJB contn

  1. Hi All,

    My understandings are -

    - Classes in java.awt package create internal threads for some processing (not very sure which are such cases/classes). Also
    - In J2EE, it is not at all recommended to create threads from the EJB container from the application program or any tool/library used to build the application logic.

    Summing up these points - is it at all recomended to use java.awt packages from EJB container ?

    Any point/clarification will be really helpful.

    Regards,
    Sourav
  2. What are you trying to do here?
  3. what in the world makes you to use AWT inside a container??@#$%
    jeeeeeeeeez

    :o)

    -Vaheesan selvarajah
  4. Hello.

    Specification says that EJB must not manage execution threads. It doesn't have matter wich way of thread management you are going to use.

    Furthermore, using AWT within EJB tier is not a very good idea. This means that your EJB will not be able to work (and to compile) untill you have AWT libraries in the classpath for your server side (this is not always the case).

    In the above, I assumed that you didn't want to manage AWT GUI from EJB. If you did, then you should consider changing design of your system.

    Alexey.
  5. Hi All,

    Thanks for your reply.

    Actually all I'm trying to do from the EJB (actually from MDB) is to call a report generation/content creation tool (Jasper Report - an open source tool) for creating a mail content. Further down the line I'm sending the mail using Java Mail API. The mail contet getting generated typiaclly contain 1/2 imgaes.

    The Jasper Report tool is a content creation tool, which gives you back final content using XML based template and any data source. It can gives back content in different formats - HTML, PDF etc.

    Now, to all my surprise, I suddenly found that this tool internally uses certain AWT classes for creating the content. The specific classes being used are -
    java.awt.BasicStroke
    java.awt.Image
    java.awt.font.TextAttribute;
    java.awt.Graphics2D;
    java.awt.GraphicsEnvironment;
    java.awt.RenderingHints;
    java.awt.Stroke;
    java.awt.font.FontRenderContext;
    java.awt.font.LineBreakMeasurer;
    java.awt.font.TextLayout;
    java.awt.geom.AffineTransform;
    java.awt.Graphics
    java.awt.image.BufferedImage;
    java.awt.print.PageFormat;
    java.awt.print.Printable;
    java.awt.print.PrinterException;
    java.awt.print.PrinterJob;
    java.awt.font.FontRenderContext;
     java.awt.font.LineBreakMeasurer;
    java.awt.font.TextLayout;
    java.awt.geom.AffineTransform;
    java.awt.print.Book;
    java.awt.print.Paper;
    java.awt.MediaTracker;
    java.awt.Panel;
    java.awt.Toolkit;

    Since we are already using this tool, I wanted to know whether there are any real hard in using these awt classes from EJB container.

    Any furtheer suggestion/pointer would be really helpful

    Regards,
    Sourav
  6. Hello again.

    I'm not a big specialist in AWT. But from the most general point of view, I think you will not have problems (not taking into account classpath dependency on AWT library) even if AWT creates threads until you don't use those threads in your EJB code. If AWT uses its own threads internaly, it's ok.

    But you may find problems if you are doing some job in AWT callbacks invoked by those additional threads. This may cause deadlocks and problems with security and transactions. This is because container usually accosiates security and transaction contexts with the threads it uses to serve clients requests. It cannot do this for threads created by AWT.