RE: Help Preventing VM Tomcat Crash

2002-02-24 Thread Kennedy Clark

Shawn,
Excellent advice!  The ByteArrayOutputStream worked beautifully.  Thank 
you.  I'm in the process of downloading 1.4 and will see if that works too.
Again, thanks a bunch!
Kennedy

At 03:31 PM 2/23/2002 -0600, Shawn Church wrote:
So much for that theory.

However, your guess is pretty close.  I found something which you might find
interesting.  This is a known bug, which you can check out here:

http://developer.java.sun.com/developer/bugParade/bugs/4502892.html

The problem occurs when the socket is prematurely closed.  The workaround is
to buffer the output via ByteArrayOutputStream, isolating the native method
from stream disconnections.

The evaluation of the bug I will include here for convenience:

snip


--
To unsubscribe:   mailto:[EMAIL PROTECTED]
For additional commands: mailto:[EMAIL PROTECTED]
Troubles with the list: mailto:[EMAIL PROTECTED]




RE: Help Preventing VM Tomcat Crash

2002-02-23 Thread Shawn Church

Looks like you are using the JDBC-ODBC bridge (maybe to an MS Access or MS
SQL Server database?), which is not thread-safe and is not intended for use
in production environments.  My guess is that one thread (the current thread
servicing the Thumbnail servlet) has a db connection open, and the next
request (the user clicking the thumbnail) opens another db connection.  This
guess is based on these lines in your exception:

An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : unknown exception code occurred at PC=0x77fb16cc
Function name=RtlTraceDatabaseEnumerate
Library=C:\WINNT\System32\ntdll.dll

If this is the case, try finding a pure Java (type 4) JDBC driver for your
database.

Shawn


-Original Message-
From: Kennedy Clark [mailto:[EMAIL PROTECTED]]
Sent: Saturday, February 23, 2002 5:36 AM
To: [EMAIL PROTECTED]
Subject: Help Preventing VM  Tomcat Crash


I'm working on a servlet that shrinks JPEG photos on the fly to create
thumbnails.  When the user selects the thumbnail page, a JSP generates HTML
that results in many calls to the thumbnail servlet.  If the user is
patient and waits for all of the thumbnails to load, everything works great
-- they can click on a thumbnail to see the full-size version of that
JPEG.  However, if the use clicks on a photo while they are still loading,
I get the exception dump and crash shown at the bottom.  Any help greatly
appreciated!  Regards, Kennedy

Here is my thumbnail servlet:
/*
  * Note: JPEG manipulation code comes from Sun:
  * http://developer.java.sun.com/developer/TechTips/1999/tt1021.html#tip1
  */
package gallery.servlet;

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.awt.Image;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;


/**
  * Return a thumbnail of the image specified in the name parameter
  */

public class Thumbnail extends HttpServlet {


 public void doGet(HttpServletRequest request,
   HttpServletResponse response)
 throws IOException, ServletException
 {
 response.setContentType(image/jpeg);
 File f = new File(request.getParameter(name));
 if (!f.exists())
 return;
 OutputStream os = response.getOutputStream();
 createThumbnail(request.getParameter(name), os, 150);
 }

 /**
  * Reads an image in a file and creates a thumbnail to the output
stream
  *
  * @param orig  The name of image file.
  * @param thumb The name of thumbnail file.
  * Will be created if necessary.
  * @param maxDim The width and height of the thumbnail must
  * be maxDim pixels or less.
  */
 public static void createThumbnail(String orig, OutputStream os, int
maxDim) {
 try {
 // Get the image from a file.
 Image inImage = new ImageIcon(orig).getImage();

 // Determine the scale.
 double scale = (double)maxDim/(double)inImage.getHeight(null);
 if (inImage.getWidth(null)  inImage.getHeight(null)) {
 scale = (double)maxDim/(double)inImage.getWidth(null);
 }

 // Determine size of new image.
 // One of them should equal maxDim.
 int scaledW = (int)(scale*inImage.getWidth(null));
 int scaledH = (int)(scale*inImage.getHeight(null));

 // Create an image buffer in which to paint on.
 BufferedImage outImage =
   new BufferedImage(scaledW, scaledH,
BufferedImage.TYPE_INT_RGB);

 // Set the scale.
 AffineTransform tx = new AffineTransform();

 // If the image is smaller than
 //the desired image size,
 // don't bother scaling.
 if (scale  1.0d) {
 tx.scale(scale, scale);
 }

 // Paint image.
 Graphics2D g2d = outImage.createGraphics();
 g2d.drawImage(inImage, tx, null);
 g2d.dispose();

 // JPEG-encode the image and write to file.
 //OutputStream os = new FileOutputStream(thumb);
 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
 encoder.encode(outImage);
 //os.close();
 } catch (IOException e) {
 e.printStackTrace();
 }
 }
}



And here is the exception/crash:
java.io.IOException: reading encoded JPEG Stream
 at sun.awt.image.codec.JPEGImageEncoderImpl.writeJPEGStream(Native
Method)
 at
sun.awt.image.codec.JPEGImageEncoderImpl.encode(JPEGImageEncoderImpl.java:47
5)

 at
sun.awt.image.codec.JPEGImageEncoderImpl.encode(JPEGImageEncoderImpl.java:23
1)
 at 

RE: Help Preventing VM Tomcat Crash

2002-02-23 Thread Kennedy Clark

Hi Shawn,

Many thanks for the note  the suggestion!  I am using MySQL as my Db and 
MM.MySQL is my driver (mm.mysql-2.0.11-bin.jar).  Given that this is a Type 
4 driver, I don't think I should be getting a native code crash involving 
database access, right?

I could be missing something, but it seems that the 
sun.awt.image.codec.JPEGImageEncoderImpl.writeJPEGStream() method (which is 
native code) is trying to write to my output stream and running into 
trouble.  I assume this is because the user has clicked on an image serving 
as a link to another web page and now Tomcat is off trying to handle the 
new page.  My best guess is that in the process of doing so, the output 
streams used by writeJPEGStream() are being torn down, but the native code 
doesn't know this and it's causing the VM to puke.  Does anyone think my 
logic makes sense?  Better yet, does anyone know a way to prevent it? :-)

Regards, Kennedy

At 09:02 AM 2/23/2002 -0600, Shawn Church wrote:
Looks like you are using the JDBC-ODBC bridge (maybe to an MS Access or MS
SQL Server database?), which is not thread-safe and is not intended for use
in production environments.  My guess is that one thread (the current thread
servicing the Thumbnail servlet) has a db connection open, and the next
request (the user clicking the thumbnail) opens another db connection.  This
guess is based on these lines in your exception:

An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : unknown exception code occurred at PC=0x77fb16cc
Function name=RtlTraceDatabaseEnumerate
Library=C:\WINNT\System32\ntdll.dll

If this is the case, try finding a pure Java (type 4) JDBC driver for your
database.

Shawn


-Original Message-
From: Kennedy Clark [mailto:[EMAIL PROTECTED]]
Sent: Saturday, February 23, 2002 5:36 AM
To: [EMAIL PROTECTED]
Subject: Help Preventing VM  Tomcat Crash


I'm working on a servlet that shrinks JPEG photos on the fly to create
thumbnails.  When the user selects the thumbnail page, a JSP generates HTML
that results in many calls to the thumbnail servlet.  If the user is
patient and waits for all of the thumbnails to load, everything works great
-- they can click on a thumbnail to see the full-size version of that
JPEG.  However, if the use clicks on a photo while they are still loading,
I get the exception dump and crash shown at the bottom.  Any help greatly
appreciated!  Regards, Kennedy

Here is my thumbnail servlet:
/*
   * Note: JPEG manipulation code comes from Sun:
   * http://developer.java.sun.com/developer/TechTips/1999/tt1021.html#tip1
   */
package gallery.servlet;

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.awt.Image;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;


/**
   * Return a thumbnail of the image specified in the name parameter
   */

public class Thumbnail extends HttpServlet {


  public void doGet(HttpServletRequest request,
HttpServletResponse response)
  throws IOException, ServletException
  {
  response.setContentType(image/jpeg);
  File f = new File(request.getParameter(name));
  if (!f.exists())
  return;
  OutputStream os = response.getOutputStream();
  createThumbnail(request.getParameter(name), os, 150);
  }

  /**
   * Reads an image in a file and creates a thumbnail to the output
stream
   *
   * @param orig  The name of image file.
   * @param thumb The name of thumbnail file.
   * Will be created if necessary.
   * @param maxDim The width and height of the thumbnail must
   * be maxDim pixels or less.
   */
  public static void createThumbnail(String orig, OutputStream os, int
maxDim) {
  try {
  // Get the image from a file.
  Image inImage = new ImageIcon(orig).getImage();

  // Determine the scale.
  double scale = (double)maxDim/(double)inImage.getHeight(null);
  if (inImage.getWidth(null)  inImage.getHeight(null)) {
  scale = (double)maxDim/(double)inImage.getWidth(null);
  }

  // Determine size of new image.
  // One of them should equal maxDim.
  int scaledW = (int)(scale*inImage.getWidth(null));
  int scaledH = (int)(scale*inImage.getHeight(null));

  // Create an image buffer in which to paint on.
  BufferedImage outImage =
new BufferedImage(scaledW, scaledH,
BufferedImage.TYPE_INT_RGB);

  // Set the scale.
  AffineTransform tx = new AffineTransform();

  // If the image is smaller than
  //the 

RE: Help Preventing VM Tomcat Crash

2002-02-23 Thread Shawn Church

So much for that theory.

However, your guess is pretty close.  I found something which you might find
interesting.  This is a known bug, which you can check out here:

http://developer.java.sun.com/developer/bugParade/bugs/4502892.html

The problem occurs when the socket is prematurely closed.  The workaround is
to buffer the output via ByteArrayOutputStream, isolating the native method
from stream disconnections.

The evaluation of the bug I will include here for convenience:

***
The JPEG library is not MT-safe.  In particular, there is a definition of
a global variable struct error_mgr ek_err which is used by all threads
for error handling -- including a setjmp buffer.  Consequently, when an
error does occur while more than one thread is executing in the native
library, it is common for that thread to longjmp to another thread's state.
It then uses the wrong JNIEnv pointer and trashes the VM.
x@x 2001-10-09

This bug has indeed been fixed in merlin-rc1, but its associated regression
test
(JPEGMultithread.java) is confusing and potentially misleading.  This is
addressed by another bug (4546112 - Reg-test JPEGMultithread.java Failing).
The regression test currently throws exceptions endlessly if bug 4502892 is
not
present, and hangs or crashes the VM if bug 4502892 is present.  This is bad
behavior for a regression test, so it will be updated in accordance with
4546112.
x@x 2001-12-19
***

Hope this helps more,
Shawn


-Original Message-
From: Kennedy Clark [mailto:[EMAIL PROTECTED]]
Sent: Saturday, February 23, 2002 2:32 PM
To: Tomcat Users List
Subject: RE: Help Preventing VM  Tomcat Crash


Hi Shawn,

Many thanks for the note  the suggestion!  I am using MySQL as my Db and
MM.MySQL is my driver (mm.mysql-2.0.11-bin.jar).  Given that this is a Type
4 driver, I don't think I should be getting a native code crash involving
database access, right?

I could be missing something, but it seems that the
sun.awt.image.codec.JPEGImageEncoderImpl.writeJPEGStream() method (which is
native code) is trying to write to my output stream and running into
trouble.  I assume this is because the user has clicked on an image serving
as a link to another web page and now Tomcat is off trying to handle the
new page.  My best guess is that in the process of doing so, the output
streams used by writeJPEGStream() are being torn down, but the native code
doesn't know this and it's causing the VM to puke.  Does anyone think my
logic makes sense?  Better yet, does anyone know a way to prevent it? :-)

Regards, Kennedy

At 09:02 AM 2/23/2002 -0600, Shawn Church wrote:
Looks like you are using the JDBC-ODBC bridge (maybe to an MS Access or MS
SQL Server database?), which is not thread-safe and is not intended for use
in production environments.  My guess is that one thread (the current
thread
servicing the Thumbnail servlet) has a db connection open, and the next
request (the user clicking the thumbnail) opens another db connection.
This
guess is based on these lines in your exception:

An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : unknown exception code occurred at PC=0x77fb16cc
Function name=RtlTraceDatabaseEnumerate
Library=C:\WINNT\System32\ntdll.dll

If this is the case, try finding a pure Java (type 4) JDBC driver for your
database.

Shawn


-Original Message-
From: Kennedy Clark [mailto:[EMAIL PROTECTED]]
Sent: Saturday, February 23, 2002 5:36 AM
To: [EMAIL PROTECTED]
Subject: Help Preventing VM  Tomcat Crash


I'm working on a servlet that shrinks JPEG photos on the fly to create
thumbnails.  When the user selects the thumbnail page, a JSP generates HTML
that results in many calls to the thumbnail servlet.  If the user is
patient and waits for all of the thumbnails to load, everything works great
-- they can click on a thumbnail to see the full-size version of that
JPEG.  However, if the use clicks on a photo while they are still loading,
I get the exception dump and crash shown at the bottom.  Any help greatly
appreciated!  Regards, Kennedy

Here is my thumbnail servlet:
/*
   * Note: JPEG manipulation code comes from Sun:
   * http://developer.java.sun.com/developer/TechTips/1999/tt1021.html#tip1
   */
package gallery.servlet;

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.awt.Image;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;


/**
   * Return a thumbnail of the image specified in the name parameter
   */

public class Thumbnail extends HttpServlet {


  public void doGet(HttpServletRequest request,
HttpServletResponse response)
  throws IOException, ServletException
  {
  response.setContentType(image/jpeg);
  File f = new File

RE: Help Preventing VM Tomcat Crash

2002-02-23 Thread Shawn Church

One more thing.  There is a fix in jdk1.4.0 which addresses this problem,
where the native code exception is handled correctly.  With this version,
the IOExceptions may be caught and treated as normal behavior.

Here's the fix:

http://developer.java.sun.com/developer/bugParade/bugs/4546112.html

Shawn


-Original Message-
From: Shawn Church [mailto:[EMAIL PROTECTED]]
Sent: Saturday, February 23, 2002 3:32 PM
To: Tomcat Users List
Subject: RE: Help Preventing VM  Tomcat Crash


So much for that theory.

However, your guess is pretty close.  I found something which you might find
interesting.  This is a known bug, which you can check out here:

http://developer.java.sun.com/developer/bugParade/bugs/4502892.html

The problem occurs when the socket is prematurely closed.  The workaround is
to buffer the output via ByteArrayOutputStream, isolating the native method
from stream disconnections.

The evaluation of the bug I will include here for convenience:

***
The JPEG library is not MT-safe.  In particular, there is a definition of
a global variable struct error_mgr ek_err which is used by all threads
for error handling -- including a setjmp buffer.  Consequently, when an
error does occur while more than one thread is executing in the native
library, it is common for that thread to longjmp to another thread's state.
It then uses the wrong JNIEnv pointer and trashes the VM.
x@x 2001-10-09

This bug has indeed been fixed in merlin-rc1, but its associated regression
test
(JPEGMultithread.java) is confusing and potentially misleading.  This is
addressed by another bug (4546112 - Reg-test JPEGMultithread.java Failing).
The regression test currently throws exceptions endlessly if bug 4502892 is
not
present, and hangs or crashes the VM if bug 4502892 is present.  This is bad
behavior for a regression test, so it will be updated in accordance with
4546112.
x@x 2001-12-19
***

Hope this helps more,
Shawn


-Original Message-
From: Kennedy Clark [mailto:[EMAIL PROTECTED]]
Sent: Saturday, February 23, 2002 2:32 PM
To: Tomcat Users List
Subject: RE: Help Preventing VM  Tomcat Crash


Hi Shawn,

Many thanks for the note  the suggestion!  I am using MySQL as my Db and
MM.MySQL is my driver (mm.mysql-2.0.11-bin.jar).  Given that this is a Type
4 driver, I don't think I should be getting a native code crash involving
database access, right?

I could be missing something, but it seems that the
sun.awt.image.codec.JPEGImageEncoderImpl.writeJPEGStream() method (which is
native code) is trying to write to my output stream and running into
trouble.  I assume this is because the user has clicked on an image serving
as a link to another web page and now Tomcat is off trying to handle the
new page.  My best guess is that in the process of doing so, the output
streams used by writeJPEGStream() are being torn down, but the native code
doesn't know this and it's causing the VM to puke.  Does anyone think my
logic makes sense?  Better yet, does anyone know a way to prevent it? :-)

Regards, Kennedy

At 09:02 AM 2/23/2002 -0600, Shawn Church wrote:
Looks like you are using the JDBC-ODBC bridge (maybe to an MS Access or MS
SQL Server database?), which is not thread-safe and is not intended for use
in production environments.  My guess is that one thread (the current
thread
servicing the Thumbnail servlet) has a db connection open, and the next
request (the user clicking the thumbnail) opens another db connection.
This
guess is based on these lines in your exception:

An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : unknown exception code occurred at PC=0x77fb16cc
Function name=RtlTraceDatabaseEnumerate
Library=C:\WINNT\System32\ntdll.dll

If this is the case, try finding a pure Java (type 4) JDBC driver for your
database.

Shawn


-Original Message-
From: Kennedy Clark [mailto:[EMAIL PROTECTED]]
Sent: Saturday, February 23, 2002 5:36 AM
To: [EMAIL PROTECTED]
Subject: Help Preventing VM  Tomcat Crash


I'm working on a servlet that shrinks JPEG photos on the fly to create
thumbnails.  When the user selects the thumbnail page, a JSP generates HTML
that results in many calls to the thumbnail servlet.  If the user is
patient and waits for all of the thumbnails to load, everything works great
-- they can click on a thumbnail to see the full-size version of that
JPEG.  However, if the use clicks on a photo while they are still loading,
I get the exception dump and crash shown at the bottom.  Any help greatly
appreciated!  Regards, Kennedy

Here is my thumbnail servlet:
/*
   * Note: JPEG manipulation code comes from Sun:
   * http://developer.java.sun.com/developer/TechTips/1999/tt1021.html#tip1
   */
package gallery.servlet;

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.awt.Image;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage