Link to home
Start Free TrialLog in
Avatar of jocelynyip
jocelynyip

asked on

Get Image

Dear Experts,

           I have a java class. This class will get the image. It is running well and no exception thrown. But, when I deploy to the linux server, and put it in the tomcat, it still can run, but, when come to period of time, this class will stop before the code below and there is no exception thrown:

            Image image = Toolkit.getDefaultToolkit().getImage(inFile);

          Once I restart my tomcat, this class can still run without error. Can someone tell me what is the problem? Any idea to overcome this problem?

          This is part of my code:

            Image image = Toolkit.getDefaultToolkit().getImage(inFile);
            MediaTracker mediaTracker = new MediaTracker(new Frame());
            mediaTracker.addImage(image, 0);
            mediaTracker.waitForID(0);
            BufferedImage sImage = new BufferedImage(width,
                  height, BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics2D = sImage.createGraphics();
            graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                  RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            graphics2D.drawImage(image, 0, 0, width, height, null);
            BufferedOutputStream out = new BufferedOutputStream(new
                  FileOutputStream(outFile));
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
            JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(sImage);
            quality = Math.max(0, Math.min(quality, 100));
            param.setQuality((float)quality / 100.0f, false);
            encoder.setJPEGEncodeParam(param);
            encoder.encode(sImage);


Regards,
  Jocelyn
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

>>this class will stop before the code below and there is no exception thrown:

Are you certain there's no exception? What is happening just prior to that code being called?
Avatar of jocelynyip
jocelynyip

ASKER

Yes, I am sure.

For an example:

System.out.println("Start Get Image!!!");
Image image = Toolkit.getDefaultToolkit().getImage(inFile);
System.out.println("End Get Image!!!");

In the console, I just can see "Start Get Image", and the println just stop here and from the console, I can't see any exception thrown. So, I know that there is problem with this code --> Image image = Toolkit.getDefaultToolkit().getImage(inFile);
>>In the console, I just can see "Start Get Image",

How can you see the console if you're running in Tomcat?

>>ut, when I deploy to the linux server, and put it in the tomcat, it still can run, but ...
e.g. if that image file is outside the web context, your code will crash in a web container
I can see it throught the log catalina.out.

My code can run for a period of time and over a period of time, the code will stop at the code Image image = Toolkit.getDefaultToolkit().getImage(inFile);

I have to restart tomcat, and my code is running. That means that everytime it down, I have to restart tomcat to make it running.
OK, so sometimes is *does* render the image ok using Tomcat ..?
yes
OK - we can rule out security issues then. Is this image by any chance a large one?
What u mean by rule out security issue? The image size is 176x134
>> What u mean by rule out security issue?

Problems due to the security policy of your web container

>>The image size is 176x134

Well i meant the file size, but i take it from that it's not large ;-)
The file is not big, ard 60kb, some is only 17kb
>>In the console, I just can see "Start Get Image", and the println just stop here

Is this *always* the case?

I'll imagine the above says 'In the log file' - it's confusing ;-)
sorry, is the log will show the println.
But you didn't answer the question:

>>Is this *always* the case?
Everyday has such problem. Quite frequent.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok, thank you.