Web Hosting Talk







View Full Version : Java servlet keeps on giving 'java.lang.OutOfMemoryError'


daweb
11-27-2004, 02:13 PM
Hello Guys,

I'm developing a Java-servlet using ImageMagick, but I keep on getting the same error.

Catalina.out keeps on giving:java.lang.OutOfMemoryErrorWhen accessing the servlet via http, it says:WebApp: Error 500
(File: //home/builder/pb_work_dir/psa_patch_7.0.4/psa/apache-modules/mod_webapp_apache2/work/jakarta-tomcat-connectors-4.1.29-src/webapp/lib/pr_warp.c Line: 398)

--------------------------------------------------------------------------------
Communication interruptedImageMagick is working perfectly in PHP. I've just installed JMagick to work with ImageMagick in Java. I hoped installing that would fix the issue, because I was already having this error before installing JMagick.

This is the sourcecode of my 'Test if ImageMagick is working in Java'-servlet:See attachment in my 2nd postThanks in advance!

daweb
11-27-2004, 02:15 PM
This file contains the sourcecode of my 'Test if ImageMagick works'-servlet.

daweb
11-29-2004, 11:03 AM
Anybody?

I haven't been making any progress. Any advise would be welcome as well. I'm a Java-newbie.

stdunbar
11-29-2004, 12:42 PM
What servlet engine are you using, Tomcat? By default the Tomcat scripts don't change the maximum amount of memory available for the Java virtual machine. Therefore, if you're using the Sun JVM the default is 64MB - not very much for image processing.

If you're using Tomcat, you can increase the amount of memory available by doing something like:

export JAVA_OPTS="-Xmx=512m"
/usr/local/tomcat/bin/startup.sh # or wherever your install is

This will allow the JVM to allocate up to 512MB. Adjust this number as needed.

daweb
11-29-2004, 01:08 PM
I already tried that. It made no difference:[root@server04 init.d]# cat tomcat4
#!/bin/sh
#
# Startup script for Tomcat 4.0, the Apache Servlet Engine
#
# chkconfig: - 80 20
# description: Tomcat 4.0 is the Apache Servlet Engine RI for Servlet 2.3/JSP 1.2
# processname: tomcat
# pidfile: /var/run/tomcat4.pid
# config: /etc/tomcat4/tomcat4.conf
#
# Gomez Henri <hgomez@users.sourceforge.net>
# Keith Irwin <keith_irwin@non.hp.com>
# Nicolas Mailhot <nicolas.mailhot@one2team.com>
#
# version 1.02 - Removed initlog support
# version 1.03 - Removed config:
# version 1.04 - tomcat will start before httpd and stop after httpd
# version 1.05 - jdk hardcoded to link /usr/java/jdk and tomcat runs as "nobody"
# version 1.06 - split up into script and config file
# version 1.07 - Rework from Nicolas ideas
# version 1.08 - Fix work dir permission at start time, switch to use tomcat4
# version 1.09 - Fix pidfile and config tags
# version 1.10 - Fallback to su direct use on systems without Redhat/Mandrake init.d functions
# version 1.11 - Fix webapps dir permissions
# version 1.12 - remove initial start/stop level for chkconfig (- 80 20)
# version 1.13 - remove chown of logs/work/temp/webapps dir, owned by tomcat4 at install time
# version 1.14 - correct the start/stop ugly hack by waiting all the threads stops
# version 1.15 - ensure we're looking for TOMCAT_USER running catalina
# version 1.16 - Add support for CATALINA_PID env var
# version 1.17 - Remove run files only tomcat started correctl
# in start area, check that tomcat is not allready running
#

# Source function library.
if [ -x /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
fi

# Get Tomcat config

TOMCAT_CFG="/etc/tomcat4/tomcat4.conf"

[ -r "$TOMCAT_CFG" ] && . "${TOMCAT_CFG}"

# Path to the tomcat launch script (direct don't use wrapper)
TOMCAT_SCRIPT=/usr/bin/dtomcat4

# Tomcat name :)
TOMCAT_PROG=tomcat4

# if TOMCAT_USER is not set, use tomcat4 like Apache HTTP server
if [ -z "$TOMCAT_USER" ]; then
TOMCAT_USER="tomcat4"
fi

# Since the daemon function will sandbox $tomcat
# no environment stuff should be defined here anymore.
# Please use the /etc/tomcat.conf file instead ; it will
# be read by the $tomcat script

RETVAL=0

# See how we were called.
start() {
echo -n "Starting $TOMCAT_PROG: "

if [ -f /var/lock/subsys/tomcat4 ] ; then
echo "process allready running"
return -1
else
export CATALINA_PID=/var/run/tomcat4.pid
export CATALINA_OPS='-Xmx1024M'
touch $CATALINA_PID
chown $TOMCAT_USER:$TOMCAT_USER $CATALINA_PID

if [ -x /etc/rc.d/init.d/functions ]; then
daemon --user $TOMCAT_USER $TOMCAT_SCRIPT start -security
else
su - $TOMCAT_USER -c "$TOMCAT_SCRIPT start -security"
fi

RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/tomcat4
return $RETVAL
fi
}

stop() {
echo -n "Stopping $TOMCAT_PROG: "

if [ -f /var/lock/subsys/tomcat4 ] ; then
if [ -x /etc/rc.d/init.d/functions ]; then
daemon --user $TOMCAT_USER $TOMCAT_SCRIPT stop
else
su - $TOMCAT_USER -c "$TOMCAT_SCRIPT stop"
fi
RETVAL=$?

if [ 0 ]; then
count=0;

if [ -f /var/run/tomcat4.pid ]; then

read kpid < /var/run/tomcat4.pid
let kwait=$SHUTDOWN_WAIT

until [ `ps --pid $kpid | grep -c $kpid` = '0' ] || [ $count -gt $kwait ]
do
echo "waiting for processes to exit";
sleep 1
let count=$count+1;
done

if [ $count -gt $kwait ]; then
echo "killing processes which didn't stop after $SHUTDOWN_WAIT seconds"
kill -9 $kpid
fi
fi

rm -f /var/lock/subsys/tomcat4 /var/run/tomcat4.pid
fi

fi
}


# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 2
start
;;
condrestart)
if [ -f /var/run/tomcat4.pid ] ; then
stop
start
fi
;;
*)
echo "Usage: $TOMCAT_PROG {start|stop|restart|condrestart}"
exit 1
esac

exit $RETVAL
[root@server04 init.d]#While running the servlet it goes to:
[root@server04 init.d]# free -m
total used free shared buffers cached
Mem: 1009 1005 3 0 149 121
-/+ buffers/cache: 734 274
Swap: 1992 35 1957
[root@server04 init.d]#

After it gave the Error500 it gives:
[root@server04 init.d]# killall -9 java
[root@server04 init.d]# free -m
total used free shared buffers cached
Mem: 1009 472 536 0 147 121
-/+ buffers/cache: 203 805
Swap: 1992 0 1992
[root@server04 init.d]#

*EDIT*
I see i misspelled cataline_opts, changing it doesn't help. The quote gives the wrong spelled parameter.

blenard
12-14-2004, 11:18 PM
If you're running cpanel you need to disable shell bombfork protection. pm me and I can take a look.

daweb
12-15-2004, 04:43 AM
Nope, Plesk-server on FC2.

blenard
12-15-2004, 11:36 AM
Login as the user Tomcat is; type java -version and tell me what happens

daweb
12-15-2004, 03:13 PM
[root@server04 root]# /usr/java/j2sdk1.4.2_06/bin/java -version
java version "1.4.2_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_06-b03)
Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)
[root@server04 root]#

blenard
12-15-2004, 03:21 PM
Ok , you did that as root; I need you to do that as the tomcat user.

So:
su - tomcat4
java -version


Also as the user tomcat4 do:
ls -al $HOME
If there's a '.profile' file please show the contents.

If you want, I can login and look for you.

blenard
12-15-2004, 03:23 PM
Do you have AOL IM?
My name is 'benlenard'