Discussion:
starting and stopping Tomcat from Java code
Oleg Lebedev
2005-12-14 23:03:36 UTC
Permalink
Hello,

I am trying to configure, start and then shutdown Tomcat from my Java
class. I am planning to have all the jars required by Tomcat on the
classpath and I would like to be able to specify the port number and
host using method calls. I would prefer not to ship Tomcat configuration
files, such as server.xml with my application and be able to configure
Tomcat from code before starting it.

I tried using Boostrap class, but it requires catalina.home and
catalina.base, which I would like to avoid using.
I tried using Embed class and it worked, but I still had to set
catalina.home so that it can find tomcat-users.xml. But, this is
acceptable.

I have not been able to shut Tomcat down from my Java code. Note that I
won't have a handle to the Catalina instance started, because Tomcat
needs to be started before my application starts in a separate VM, and
then killed when my application exists.

I would appreciate any feedback on how to do this or what Tomcat classes
I should take a look at.

Thanks.

Oleg
Stas Ostapenko
2005-12-14 23:28:19 UTC
Permalink
Maybe this can help (Embed with Tomcat) ?
http://www.vsj.co.uk/articles/display.asp?id=319
Post by Oleg Lebedev
Hello,
I am trying to configure, start and then shutdown Tomcat from my Java
class. I am planning to have all the jars required by Tomcat on the
classpath and I would like to be able to specify the port number and
host using method calls. I would prefer not to ship Tomcat configuration
files, such as server.xml with my application and be able to configure
Tomcat from code before starting it.
I tried using Boostrap class, but it requires catalina.home and
catalina.base, which I would like to avoid using.
I tried using Embed class and it worked, but I still had to set
catalina.home so that it can find tomcat-users.xml. But, this is
acceptable.
I have not been able to shut Tomcat down from my Java code. Note that I
won't have a handle to the Catalina instance started, because Tomcat
needs to be started before my application starts in a separate VM, and
then killed when my application exists.
I would appreciate any feedback on how to do this or what Tomcat classes
I should take a look at.
Thanks.
Oleg
Wendy Smoak
2005-12-14 23:44:01 UTC
Permalink
Post by Oleg Lebedev
I am trying to configure, start and then shutdown Tomcat from my Java
class.
No idea if it will do what you want, but that requirement made me
think of Cargo:
http://cargo.codehaus.org/

--
Wendy
Oleg Lebedev
2005-12-15 00:15:12 UTC
Permalink
Stas,

This looks like a great article, and will help me to get embedded Tomcat
working. But how do I stop a running Tomcat instance from java?

Thanks.

Oleg

-----Original Message-----
From: Stas Ostapenko [mailto:***@gmail.com]
Sent: Wednesday, December 14, 2005 4:28 PM
To: Tomcat Users List
Subject: Re: starting and stopping Tomcat from Java code

Maybe this can help (Embed with Tomcat) ?
http://www.vsj.co.uk/articles/display.asp?id=319
Post by Oleg Lebedev
Hello,
I am trying to configure, start and then shutdown Tomcat from my Java
class. I am planning to have all the jars required by Tomcat on the
classpath and I would like to be able to specify the port number and
host using method calls. I would prefer not to ship Tomcat
configuration files, such as server.xml with my application and be
able to configure Tomcat from code before starting it.
I tried using Boostrap class, but it requires catalina.home and
catalina.base, which I would like to avoid using.
I tried using Embed class and it worked, but I still had to set
catalina.home so that it can find tomcat-users.xml. But, this is
acceptable.
I have not been able to shut Tomcat down from my Java code. Note that
I won't have a handle to the Catalina instance started, because Tomcat
needs to be started before my application starts in a separate VM, and
then killed when my application exists.
I would appreciate any feedback on how to do this or what Tomcat
classes I should take a look at.
Thanks.
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org


--
This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.
If you have questions about this email, please contact the IT Help Desk.

Mail
Oleg Lebedev
2005-12-15 00:27:15 UTC
Permalink
Thanks, Wendy.

I looked at cargo and it seems that it requires the container to be
installed on the local machine in order to be able to start or stop it.

In my case I have Tomcat running on some machine with a known IP address
and port number. I need to be able to send a shutdown command to that
Tomcat instance and have it stutdown itself.

I just noticed this piece of code in Catalina.stopServer(String[]):

Socket socket = new Socket("127.0.0.1",
server.getPort());
OutputStream stream = socket.getOutputStream();
String shutdown = server.getShutdown();
for (int i = 0; i < shutdown.length(); i++)
stream.write(shutdown.charAt(i));
stream.flush();
stream.close();
socket.close();

This may be what I need to use in my Java class to shut down the local
Tomcat instance.

Any ideas on whether this is the right way to shut down a stand-alone
Tomcat instance?

Thanks.

Oleg

-----Original Message-----
From: Wendy Smoak [mailto:***@gmail.com]
Sent: Wednesday, December 14, 2005 4:44 PM
To: Tomcat Users List
Subject: Re: starting and stopping Tomcat from Java code
Post by Oleg Lebedev
I am trying to configure, start and then shutdown Tomcat from my Java
class.
No idea if it will do what you want, but that requirement made me think
of Cargo:
http://cargo.codehaus.org/

--
Wendy

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org


--
This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.
If you have questions about this email, please contact the IT Help Desk.

Mail
Iannis Hanen
2005-12-15 00:35:04 UTC
Permalink
Hi Oleg,

The piece of code you just mentioned is what lies behind the <server>
tag in the server.xml file. You can set the <server> tag this way:

<Server port="1234" shutdown="myShutdown">

If you connect to port 1234 on the tomcat machine and type in the
"myShutdown" password, tomcat will shutdown. However, I am pretty sure
that this port is opened only for callers from localhost. So, if you
intend to stop it remotely, this may not be possible. You may have to
use a proxy of some kind to relay your call so that tomcat believes the
call comes from localhost.

Iannis

-----Original Message-----
From: Oleg Lebedev [mailto:***@waterford.org]
Sent: Wednesday, December 14, 2005 4:27 PM
To: Tomcat Users List
Subject: RE: starting and stopping Tomcat from Java code

Thanks, Wendy.

I looked at cargo and it seems that it requires the container to be
installed on the local machine in order to be able to start or stop it.

In my case I have Tomcat running on some machine with a known IP address
and port number. I need to be able to send a shutdown command to that
Tomcat instance and have it stutdown itself.

I just noticed this piece of code in Catalina.stopServer(String[]):

Socket socket = new Socket("127.0.0.1",
server.getPort());
OutputStream stream = socket.getOutputStream();
String shutdown = server.getShutdown();
for (int i = 0; i < shutdown.length(); i++)
stream.write(shutdown.charAt(i));
stream.flush();
stream.close();
socket.close();

This may be what I need to use in my Java class to shut down the local
Tomcat instance.

Any ideas on whether this is the right way to shut down a stand-alone
Tomcat instance?

Thanks.

Oleg

-----Original Message-----
From: Wendy Smoak [mailto:***@gmail.com]
Sent: Wednesday, December 14, 2005 4:44 PM
To: Tomcat Users List
Subject: Re: starting and stopping Tomcat from Java code
Post by Oleg Lebedev
I am trying to configure, start and then shutdown Tomcat from my Java
class.
No idea if it will do what you want, but that requirement made me think
of Cargo:
http://cargo.codehaus.org/

--
Wendy

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org


--
This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.
If you have questions about this email, please contact the IT Help Desk.

Mail


---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Oleg Lebedev
2005-12-15 00:45:45 UTC
Permalink
Great, sending that shutdown command to a Tomcat server started with
server.xml file on the disk worked.

But how can I specify what the server shutdown command is when I start
the server in embedded mode on a certain port? (See code below)


private static void startTomcat(){
String hostName = "localhost";
int port = 8888;

String commonPath = "C:/myapp";
String catalinaHome = commonPath + "/tomcat";
System.setProperty("catalina.home", catalinaHome);

Embedded embedded = new Embedded();

MemoryRealm memRealm = new MemoryRealm();
embedded.setRealm(memRealm);

Engine engine = embedded.createEngine();

Host host = embedded.createHost(hostName, "");
engine.addChild(host);
Context rootCtx = embedded.createContext("", "/");
rootCtx.setPrivileged(true);
host.addChild(rootCtx);
embedded.addEngine(engine);

Connector httpConnector = embedded.createConnector(
(java.net.InetAddress) null, port,
false);

embedded.addConnector(httpConnector);
embedded.start();
}


-----Original Message-----
From: Iannis Hanen [mailto:***@bluejungle.com]
Sent: Wednesday, December 14, 2005 5:35 PM
To: Tomcat Users List
Cc: Iannis Hanen
Subject: RE: starting and stopping Tomcat from Java code

Hi Oleg,

The piece of code you just mentioned is what lies behind the <server>
tag in the server.xml file. You can set the <server> tag this way:

<Server port="1234" shutdown="myShutdown">

If you connect to port 1234 on the tomcat machine and type in the
"myShutdown" password, tomcat will shutdown. However, I am pretty sure
that this port is opened only for callers from localhost. So, if you
intend to stop it remotely, this may not be possible. You may have to
use a proxy of some kind to relay your call so that tomcat believes the
call comes from localhost.

Iannis

-----Original Message-----
From: Oleg Lebedev [mailto:***@waterford.org]
Sent: Wednesday, December 14, 2005 4:27 PM
To: Tomcat Users List
Subject: RE: starting and stopping Tomcat from Java code

Thanks, Wendy.

I looked at cargo and it seems that it requires the container to be
installed on the local machine in order to be able to start or stop it.

In my case I have Tomcat running on some machine with a known IP address
and port number. I need to be able to send a shutdown command to that
Tomcat instance and have it stutdown itself.

I just noticed this piece of code in Catalina.stopServer(String[]):

Socket socket = new Socket("127.0.0.1",
server.getPort());
OutputStream stream = socket.getOutputStream();
String shutdown = server.getShutdown();
for (int i = 0; i < shutdown.length(); i++)
stream.write(shutdown.charAt(i));
stream.flush();
stream.close();
socket.close();

This may be what I need to use in my Java class to shut down the local
Tomcat instance.

Any ideas on whether this is the right way to shut down a stand-alone
Tomcat instance?

Thanks.

Oleg

-----Original Message-----
From: Wendy Smoak [mailto:***@gmail.com]
Sent: Wednesday, December 14, 2005 4:44 PM
To: Tomcat Users List
Subject: Re: starting and stopping Tomcat from Java code
Post by Oleg Lebedev
I am trying to configure, start and then shutdown Tomcat from my Java
class.
No idea if it will do what you want, but that requirement made me think
of Cargo:
http://cargo.codehaus.org/

--
Wendy

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org


--
This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.
If you have questions about this email, please contact the IT Help Desk.

Mail


---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org


--
This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.
If you have questions about this email, please contact the IT Help Desk.

Mail
andy gordon
2005-12-15 02:57:49 UTC
Permalink
There is an MBean for the Server and I believe that you can specify the command there.

Oleg Lebedev <***@waterford.org> wrote:
Great, sending that shutdown command to a Tomcat server started with
server.xml file on the disk worked.

But how can I specify what the server shutdown command is when I start
the server in embedded mode on a certain port? (See code below)


private static void startTomcat(){
String hostName = "localhost";
int port = 8888;

String commonPath = "C:/myapp";
String catalinaHome = commonPath + "/tomcat";
System.setProperty("catalina.home", catalinaHome);

Embedded embedded = new Embedded();

MemoryRealm memRealm = new MemoryRealm();
embedded.setRealm(memRealm);

Engine engine = embedded.createEngine();

Host host = embedded.createHost(hostName, "");
engine.addChild(host);
Context rootCtx = embedded.createContext("", "/");
rootCtx.setPrivileged(true);
host.addChild(rootCtx);
embedded.addEngine(engine);

Connector httpConnector = embedded.createConnector(
(java.net.InetAddress) null, port,
false);

embedded.addConnector(httpConnector);
embedded.start();
}


-----Original Message-----
From: Iannis Hanen [mailto:***@bluejungle.com]
Sent: Wednesday, December 14, 2005 5:35 PM
To: Tomcat Users List
Cc: Iannis Hanen
Subject: RE: starting and stopping Tomcat from Java code

Hi Oleg,

The piece of code you just mentioned is what lies behind the
tag in the server.xml file. You can set the tag this way:



If you connect to port 1234 on the tomcat machine and type in the
"myShutdown" password, tomcat will shutdown. However, I am pretty sure
that this port is opened only for callers from localhost. So, if you
intend to stop it remotely, this may not be possible. You may have to
use a proxy of some kind to relay your call so that tomcat believes the
call comes from localhost.

Iannis

-----Original Message-----
From: Oleg Lebedev [mailto:***@waterford.org]
Sent: Wednesday, December 14, 2005 4:27 PM
To: Tomcat Users List
Subject: RE: starting and stopping Tomcat from Java code

Thanks, Wendy.

I looked at cargo and it seems that it requires the container to be
installed on the local machine in order to be able to start or stop it.

In my case I have Tomcat running on some machine with a known IP address
and port number. I need to be able to send a shutdown command to that
Tomcat instance and have it stutdown itself.

I just noticed this piece of code in Catalina.stopServer(String[]):

Socket socket = new Socket("127.0.0.1",
server.getPort());
OutputStream stream = socket.getOutputStream();
String shutdown = server.getShutdown();
for (int i = 0; i < shutdown.length(); i++)
stream.write(shutdown.charAt(i));
stream.flush();
stream.close();
socket.close();

This may be what I need to use in my Java class to shut down the local
Tomcat instance.

Any ideas on whether this is the right way to shut down a stand-alone
Tomcat instance?

Thanks.

Oleg

-----Original Message-----
From: Wendy Smoak [mailto:***@gmail.com]
Sent: Wednesday, December 14, 2005 4:44 PM
To: Tomcat Users List
Subject: Re: starting and stopping Tomcat from Java code
Post by Oleg Lebedev
I am trying to configure, start and then shutdown Tomcat from my Java
class.
No idea if it will do what you want, but that requirement made me think
of Cargo:
http://cargo.codehaus.org/

--
Wendy

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org


--
This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.
If you have questions about this email, please contact the IT Help Desk.

Mail


---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org


--
This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.
If you have questions about this email, please contact the IT Help Desk.

Mail


---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org





---------------------------------
Yahoo! Shopping
Find Great Deals on Holiday Gifts at Yahoo! Shopping
Bill Barker
2005-12-15 03:14:53 UTC
Permalink
Urm, something like:
tomcat.stop();

where 'tomcat' is your Embedded instance?

"Oleg Lebedev" <***@waterford.org> wrote in message news:***@wistomail01.waterford.org...
Hello,

I am trying to configure, start and then shutdown Tomcat from my Java
class. I am planning to have all the jars required by Tomcat on the
classpath and I would like to be able to specify the port number and
host using method calls. I would prefer not to ship Tomcat configuration
files, such as server.xml with my application and be able to configure
Tomcat from code before starting it.

I tried using Boostrap class, but it requires catalina.home and
catalina.base, which I would like to avoid using.
I tried using Embed class and it worked, but I still had to set
catalina.home so that it can find tomcat-users.xml. But, this is
acceptable.

I have not been able to shut Tomcat down from my Java code. Note that I
won't have a handle to the Catalina instance started, because Tomcat
needs to be started before my application starts in a separate VM, and
then killed when my application exists.

I would appreciate any feedback on how to do this or what Tomcat classes
I should take a look at.

Thanks.

Oleg
Wade Chandler
2005-12-15 04:02:58 UTC
Permalink
Post by Bill Barker
tomcat.stop();
where 'tomcat' is your Embedded instance?
Hello,
I am trying to configure, start and then shutdown
Tomcat from my Java
class. I am planning to have all the jars required
by Tomcat on the
classpath and I would like to be able to specify the
port number and
host using method calls. I would prefer not to ship
Tomcat configuration
files, such as server.xml with my application and be
able to configure
Tomcat from code before starting it.
I tried using Boostrap class, but it requires
catalina.home and
catalina.base, which I would like to avoid using.
I tried using Embed class and it worked, but I still
had to set
catalina.home so that it can find tomcat-users.xml.
But, this is
acceptable.
I have not been able to shut Tomcat down from my
Java code. Note that I
won't have a handle to the Catalina instance
started, because Tomcat
needs to be started before my application starts in
a separate VM, and
then killed when my application exists.
I would appreciate any feedback on how to do this or
what Tomcat classes
I should take a look at.
Thanks.
Oleg
---------------------------------------------------------------------
I guess if you know how to do this when you do have an
instance in the same VM then you can simply use the
web application you are using in the backend. I
assume you are connecting to this server from clients
or something. In the code creating the instance store
the Object in a static variable in a package you
install in the extensions directory of the executing
vm or the trusted libraries for the tomcat instance.
This way they are available to all classes in the
Tomcat instance. Then you can shut it down from your
other application by accessing a servlet or soemthing.
You might have to play around with the security
access for the methods though...not sure. Anyways,
basically you just make a simple class so you can
install it like that. It won't be something you
change much and it's sole purpose is so it's part of
your class package and system. It could be as simple
as a single class with nothing but a static instance
of the Tomcat server so you can access it.

Just a simple idea, but should work unless you can
simply edit the security file to allow your web app
code to access the internal tomcat engine it's running
in. Which you should be able to do that as well.

Wade
Oleg Lebedev
2005-12-15 04:50:13 UTC
Permalink
Yes, that would work if I had a handle to the embedded instance. The thing is that embedded tomcat is running in a separate VM and I need to be able to shut it down. I don't really need to use Embedded class if only I could get Bootstrap or Catalina classes to work without having to have the whole tomcat directory on disk.


-----Original Message-----
From: news on behalf of Bill Barker
Sent: Wed 12/14/2005 8:14 PM
To: ***@tomcat.apache.org
Subject: Re: starting and stopping Tomcat from Java code

Urm, something like:
tomcat.stop();

where 'tomcat' is your Embedded instance?

"Oleg Lebedev" <***@waterford.org> wrote in message news:***@wistomail01.waterford.org...
Hello,

I am trying to configure, start and then shutdown Tomcat from my Java
class. I am planning to have all the jars required by Tomcat on the
classpath and I would like to be able to specify the port number and
host using method calls. I would prefer not to ship Tomcat configuration
files, such as server.xml with my application and be able to configure
Tomcat from code before starting it.

I tried using Boostrap class, but it requires catalina.home and
catalina.base, which I would like to avoid using.
I tried using Embed class and it worked, but I still had to set
catalina.home so that it can find tomcat-users.xml. But, this is
acceptable.

I have not been able to shut Tomcat down from my Java code. Note that I
won't have a handle to the Catalina instance started, because Tomcat
needs to be started before my application starts in a separate VM, and
then killed when my application exists.

I would appreciate any feedback on how to do this or what Tomcat classes
I should take a look at.

Thanks.

Oleg





---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
If you have questions about this email, please
contact the IT Help Desk.

Mail
andy gordon
2005-12-15 12:15:31 UTC
Permalink
Oleg,

Have you looked into managing the tomcat instance with MBeans. All you need to do is establish a connection to the other JVM with an MBeanServerConnection instance. This does require a port to be exposed from Tomcat for remote monitoring. But once you have the connection you can do what you want with the remote Tomcat. Just look at how JConsole monitors/manages remote JVM applications for an example.

HTH

- andy

Oleg Lebedev <***@waterford.org> wrote:
Yes, that would work if I had a handle to the embedded instance. The thing is that embedded tomcat is running in a separate VM and I need to be able to shut it down. I don't really need to use Embedded class if only I could get Bootstrap or Catalina classes to work without having to have the whole tomcat directory on disk.


-----Original Message-----
From: news on behalf of Bill Barker
Sent: Wed 12/14/2005 8:14 PM
To: ***@tomcat.apache.org
Subject: Re: starting and stopping Tomcat from Java code

Urm, something like:
tomcat.stop();

where 'tomcat' is your Embedded instance?

"Oleg Lebedev" wrote in message news:***@wistomail01.waterford.org...
Hello,

I am trying to configure, start and then shutdown Tomcat from my Java
class. I am planning to have all the jars required by Tomcat on the
classpath and I would like to be able to specify the port number and
host using method calls. I would prefer not to ship Tomcat configuration
files, such as server.xml with my application and be able to configure
Tomcat from code before starting it.

I tried using Boostrap class, but it requires catalina.home and
catalina.base, which I would like to avoid using.
I tried using Embed class and it worked, but I still had to set
catalina.home so that it can find tomcat-users.xml. But, this is
acceptable.

I have not been able to shut Tomcat down from my Java code. Note that I
won't have a handle to the Catalina instance started, because Tomcat
needs to be started before my application starts in a separate VM, and
then killed when my application exists.

I would appreciate any feedback on how to do this or what Tomcat classes
I should take a look at.

Thanks.

Oleg





---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
If you have questions about this email, please
contact the IT Help Desk.

Mail



---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org





---------------------------------
Yahoo! Shopping
Find Great Deals on Holiday Gifts at Yahoo! Shopping
Andrievsky Dmaitry
2005-12-19 08:58:46 UTC
Permalink
Hello users,

About a half a year ago I've found that my webapp works fine in
development environment, but leaks memory in production one.
I've searched through all the code, found a few minor errors, but it
didn't help.
(of course, tag pooling are disabled completely)

So then i've tried to use profiler, looking on alien classes.
(I've tried before too, but my attention was concentrated on my own classes)

And then i've found lots of
org.apache.jasper.runtime.PageContextImpl
from which there were a lot of references to the objects, that i've
treated as dead.


All PageContextImpl's lived at
org.apache.jasper.runtime.JspFactoryImpl.pool


There are property of org.apache.jasper.runtime.JspFactoryImpl, named
USE_POOL, which rules pool usage, but it is private,
and i've not found any way to set it to "false" from outside.
Initially it's "true".

So, i've set it to "false" directly in code,
rebuilt tomcat and replaced files ${CATALINA_HOME}/common/lib/jasper-*.jar
from production environment with fresh ones.

So, it seems that the problem is successfully solved.
As far as I can see there no more memory leakage.

I think it would be useful to allow users to set property of
org.apache.jasper.runtime.JspFactoryImpl.USE_POOL from config files or
in any other way, without rebuilding entire tomcat application.

P.S.
In fact, I think, it's not REAL memory leak - memory usage, may be,
will stop grow on some large value (2+ GB, when pool become full), but i have not such
amount of memory.
Now memory usage about 100-200 mb after full gc, depending on amount
of currently working users.

P.P.S What seems to me interesting.
Although before putting PageContextImpl into pool JspFactoryImpl calls
pc.release(), and inside the method all links must become null (or
not?..) and referenced objects must become available to gc, they are not.
May be it is the root of the problem?..

BTW disabling of pool solves the problem completely...
--
Best regards,
Dmitry Andrievsky mailto:***@teztour.com
Anoop kumar V
2005-12-26 06:24:37 UTC
Permalink
I think this is a great finding - it will certainly help all those teams
faced with the Out of memory errors which curiously pops up oly after we
move the code to production..

I hope you will have the tomcat developers look into this by sending this to
tomcat-developers forum.

THanks,
Anoop
Post by Andrievsky Dmaitry
Hello users,
About a half a year ago I've found that my webapp works fine in
development environment, but leaks memory in production one.
I've searched through all the code, found a few minor errors, but it
didn't help.
(of course, tag pooling are disabled completely)
So then i've tried to use profiler, looking on alien classes.
(I've tried before too, but my attention was concentrated on my own classes)
And then i've found lots of
org.apache.jasper.runtime.PageContextImpl
from which there were a lot of references to the objects, that i've
treated as dead.
All PageContextImpl's lived at
org.apache.jasper.runtime.JspFactoryImpl.pool
There are property of org.apache.jasper.runtime.JspFactoryImpl, named
USE_POOL, which rules pool usage, but it is private,
and i've not found any way to set it to "false" from outside.
Initially it's "true".
So, i've set it to "false" directly in code,
rebuilt tomcat and replaced files ${CATALINA_HOME}/common/lib/jasper-*.jar
from production environment with fresh ones.
So, it seems that the problem is successfully solved.
As far as I can see there no more memory leakage.
I think it would be useful to allow users to set property of
org.apache.jasper.runtime.JspFactoryImpl.USE_POOL from config files or
in any other way, without rebuilding entire tomcat application.
P.S.
In fact, I think, it's not REAL memory leak - memory usage, may be,
will stop grow on some large value (2+ GB, when pool become full), but i have not such
amount of memory.
Now memory usage about 100-200 mb after full gc, depending on amount
of currently working users.
P.P.S What seems to me interesting.
Although before putting PageContextImpl into pool JspFactoryImpl calls
pc.release(), and inside the method all links must become null (or
not?..) and referenced objects must become available to gc, they are not.
May be it is the root of the problem?..
BTW disabling of pool solves the problem completely...
--
Best regards,
---------------------------------------------------------------------
--
Thanks and best regards,
Anoop
Àíäðèåâñêèé Äìèòðèé
2005-12-27 09:30:18 UTC
Permalink
Hello Anoop,
Post by Anoop kumar V
I hope you will have the tomcat developers look into this by sending this to
tomcat-developers forum.
I did, and they have already fixed it up in one of recent svn (is it
the same as cvs?..) commit.
May be not because of my letter, though :)

20.dec.05:
subject: svn commit: r358036 - in /tomcat/jasper/tc5.5.x/jasper2/src/share/org/apache/jasper/runtime: BodyContentImpl.java JspFactoryImpl.java
Post by Anoop kumar V
Modified: tomcat/jasper/tc5.5.x/jasper2/src/share/org/apache/jasper/runtime/JspFactoryImpl.java
URL: http://svn.apache.org/viewcvs/tomcat/jasper/tc5.5.x/jasper2/src/share/org/apache/jasper/runtime/JspFactoryImpl.java?rev=358036&r1=358035&r2=358036&view=diff
==============================================================================
--- tomcat/jasper/tc5.5.x/jasper2/src/share/org/apache/jasper/runtime/JspFactoryImpl.java (original)
+++ tomcat/jasper/tc5.5.x/jasper2/src/share/org/apache/jasper/runtime/JspFactoryImpl.java Tue Dec 20 09:02:33 2005
@@ -40,9 +40,10 @@
private Log log = LogFactory.getLog(JspFactoryImpl.class);
private static final String SPEC_VERSION = "2.0";
- private static final boolean USE_POOL = true;
+ private static final boolean USE_POOL =
+ Boolean.parseBoolean(System.getProperty("org.apache.jasper.runtime.JspFactoryImpl.USE_POOL", "true"));
I think this is a great finding - it will certainly help all those teams
faced with the Out of memory errors which curiously pops up oly after we
move the code to production..
I hope you will have the tomcat developers look into this by sending this to
tomcat-developers forum.
THanks,
Anoop
Post by Andrievsky Dmaitry
Hello users,
About a half a year ago I've found that my webapp works fine in
development environment, but leaks memory in production one.
I've searched through all the code, found a few minor errors, but it
didn't help.
(of course, tag pooling are disabled completely)
So then i've tried to use profiler, looking on alien classes.
(I've tried before too, but my attention was concentrated on my own classes)
And then i've found lots of
org.apache.jasper.runtime.PageContextImpl
from which there were a lot of references to the objects, that i've
treated as dead.
All PageContextImpl's lived at
org.apache.jasper.runtime.JspFactoryImpl.pool
There are property of org.apache.jasper.runtime.JspFactoryImpl, named
USE_POOL, which rules pool usage, but it is private,
and i've not found any way to set it to "false" from outside.
Initially it's "true".
So, i've set it to "false" directly in code,
rebuilt tomcat and replaced files
${CATALINA_HOME}/common/lib/jasper-*.jar
from production environment with fresh ones.
So, it seems that the problem is successfully solved.
As far as I can see there no more memory leakage.
I think it would be useful to allow users to set property of
org.apache.jasper.runtime.JspFactoryImpl.USE_POOL from config files or
in any other way, without rebuilding entire tomcat application.
P.S.
In fact, I think, it's not REAL memory leak - memory usage, may be,
will stop grow on some large value (2+ GB, when pool become full), but i have not such
amount of memory.
Now memory usage about 100-200 mb after full gc, depending on amount
of currently working users.
P.P.S What seems to me interesting.
Although before putting PageContextImpl into pool JspFactoryImpl calls
pc.release(), and inside the method all links must become null (or
not?..) and referenced objects must become available to gc, they are not.
May be it is the root of the problem?..
BTW disabling of pool solves the problem completely...
--
Best regards,
---------------------------------------------------------------------
--
Thanks and best regards,
Anoop
--
Best regards,
Äìèòðèé Àíäðèåâñêèé mailto:***@teztour.com
Oleg Lebedev
2005-12-15 16:34:45 UTC
Permalink
Andy, thanks for the hint. It seems like the right solution for our
problem.

We had to get this working by today, so we ended up extending Embedded
class and provided shutdown hooks just like Catalina class does, but
without requiring server.xml configuration. Using the new class we can
start a tomcat instance and shutdown a remote tomcat instance by sending
a shutdown command to a certain host and port.
Thanks everybody for your help.

Regards.

Oleg

-----Original Message-----
From: andy gordon [mailto:***@yahoo.com]
Sent: Thursday, December 15, 2005 5:16 AM
To: Tomcat Users List
Subject: RE: Re: starting and stopping Tomcat from Java code

Oleg,

Have you looked into managing the tomcat instance with MBeans. All you
need to do is establish a connection to the other JVM with an
MBeanServerConnection instance. This does require a port to be exposed
from Tomcat for remote monitoring. But once you have the connection you
can do what you want with the remote Tomcat. Just look at how JConsole
monitors/manages remote JVM applications for an example.

HTH

- andy

Oleg Lebedev <***@waterford.org> wrote:
Yes, that would work if I had a handle to the embedded instance. The
thing is that embedded tomcat is running in a separate VM and I need to
be able to shut it down. I don't really need to use Embedded class if
only I could get Bootstrap or Catalina classes to work without having to
have the whole tomcat directory on disk.


-----Original Message-----
From: news on behalf of Bill Barker
Sent: Wed 12/14/2005 8:14 PM
To: ***@tomcat.apache.org
Subject: Re: starting and stopping Tomcat from Java code

Urm, something like:
tomcat.stop();

where 'tomcat' is your Embedded instance?

"Oleg Lebedev" wrote in message news:***@wistomail01.waterford.org...
Hello,

I am trying to configure, start and then shutdown Tomcat from my Java
class. I am planning to have all the jars required by Tomcat on the
classpath and I would like to be able to specify the port number and
host using method calls. I would prefer not to ship Tomcat configuration
files, such as server.xml with my application and be able to configure
Tomcat from code before starting it.

I tried using Boostrap class, but it requires catalina.home and
catalina.base, which I would like to avoid using.
I tried using Embed class and it worked, but I still had to set
catalina.home so that it can find tomcat-users.xml. But, this is
acceptable.

I have not been able to shut Tomcat down from my Java code. Note that I
won't have a handle to the Catalina instance started, because Tomcat
needs to be started before my application starts in a separate VM, and
then killed when my application exists.

I would appreciate any feedback on how to do this or what Tomcat classes
I should take a look at.

Thanks.

Oleg





---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org


--
This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.
If you have questions about this email, please contact the IT Help Desk.

Mail



---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org





---------------------------------
Yahoo! Shopping
Find Great Deals on Holiday Gifts at Yahoo! Shopping
--
This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.
If you have questions about this email, please contact the IT Help Desk.

Mail
Loading...