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(imag e, 0);
mediaTracker.waitForID(0);
BufferedImage sImage = new BufferedImage(width,
height, BufferedImage.TYPE_INT_RGB );
Graphics2D graphics2D = sImage.createGraphics();
graphics2D.setRenderingHin t(Renderin gHints.KEY _INTERPOLA TION,
RenderingHints.VALUE_INTER POLATION_B ILINEAR);
graphics2D.drawImage(image , 0, 0, width, height, null);
BufferedOutputStream out = new BufferedOutputStream(new
FileOutputStream(outFile)) ;
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncode r(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEnco deParam(sI mage);
quality = Math.max(0, Math.min(quality, 100));
param.setQuality((float)qu ality / 100.0f, false);
encoder.setJPEGEncodeParam (param);
encoder.encode(sImage);
Regards,
Jocelyn
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(
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(
MediaTracker mediaTracker = new MediaTracker(new Frame());
mediaTracker.addImage(imag
mediaTracker.waitForID(0);
BufferedImage sImage = new BufferedImage(width,
height, BufferedImage.TYPE_INT_RGB
Graphics2D graphics2D = sImage.createGraphics();
graphics2D.setRenderingHin
RenderingHints.VALUE_INTER
graphics2D.drawImage(image
BufferedOutputStream out = new BufferedOutputStream(new
FileOutputStream(outFile))
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncode
JPEGEncodeParam param = encoder.getDefaultJPEGEnco
quality = Math.max(0, Math.min(quality, 100));
param.setQuality((float)qu
encoder.setJPEGEncodeParam
encoder.encode(sImage);
Regards,
Jocelyn
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);
For an example:
System.out.println("Start Get Image!!!");
Image image = Toolkit.getDefaultToolkit(
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(
>>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 ...
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
ASKER
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.
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(
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 ..?
ASKER
yes
OK - we can rule out security issues then. Is this image by any chance a large one?
ASKER
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 ;-)
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 ;-)
ASKER
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 ;-)
Is this *always* the case?
I'll imagine the above says 'In the log file' - it's confusing ;-)
ASKER
sorry, is the log will show the println.
But you didn't answer the question:
>>Is this *always* the case?
>>Is this *always* the case?
ASKER
Everyday has such problem. Quite frequent.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok, thank you.
Are you certain there's no exception? What is happening just prior to that code being called?