> Would you expand on option 2.

A Java thread is a sequence of execution of Java bytecode on a JVM.
Obviously, there can be multiple threads per JVM. A JVM is a native
operating system process interpreting (sometimes compiling on the fly) the
bytecode of at least one Java thread. Since there can be multiple processes
per machine, there can be multiple JVMs per machine. Ideally, these JVMs are
completely separated, at least their address space (memory) is. Sometimes an
operating system provides native threads. These are threads of execution of
machine instructions on the real machine. There can be multiple native
threads per native process. Thus, it is possible to map native threads to
Java threads: the JVM process contains multiple real threads, each executing
one thread of bytecode. I don't think the Sun's JVM does that, but I'm not
sure.

You just have to make sure that the monitoring thread is not executed inside
the same JVM that runs the application to be monitored.

> Why is this a thread rather than a java app that is started on system
> startup ?

Option 2 IS a Java application. It consists of a single Java thread (the one
running the main() method). But it is started only once and it repeats
internally - note the infinite while() loop. A cronjob is a Unix process
that is repeated externally. I use the term externally, because it is
started all over again periodically by an 'higher power', i.e. CRON.
Cronjobs don't usually contain infinite loops. Whether to use internal or
external repetition depends on the situation: external repetetion is more
time consuming but it releases all resources, e.g. memory after each
iteration. Internal repetition is fast but it blocks resources forever,
basically. So if something needs to be executed once every minute I would
strongly suggest internal repetition. If it needs to run once a day only, I
would suggest external repetition.

import java.net.*;
public class Main {
    public void main( String[] args ) {
        while(true) {
            URL url = new URL( "http://localhost:8080/examples"; );
            URLConnection con = url.openConnection();
            con.setUseCaches( false );
            con.connect();
            if( con.getContentLength() > 0 ) {
                // restart tomcat
            }
            // cleanup
            Thread.getCurrentThread().sleep( 100 ); // or so, I'm not sure
        }
    }
}


----- Original Message -----
From: "Ron Day" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <[EMAIL PROTECTED]>
Sent: Tuesday, February 25, 2003 8:00 PM
Subject: RE: crontab problems


>
>
> Ron
>
> -----Original Message-----
> From: Hannes Schmidt [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, February 25, 2003 12:50 PM
> To: Tomcat Users List
> Subject: Re: crontab problems
>
>
> There's not a single JVM per machine. Even if the JVM running Tomcat
inside
> it is crashed, it's prefectly ok to start another one testing for the
> existence or availability of Tomcat and/or a webapp. That will work. It's
> just that this solution is a little awkward. Let me summarize the
> alternatives:
>
> 1) A cronjob shell script using wget as John suggested.
>
> 2) A Java Thread running in a different UNIX process, i.e. JVM which
> repeatedly tests the webapp's availability like I suggested in my first
> posting. That thread runs in a loop and is NOT started regularly by cron
but
> once when the system starts (aka. init script).
>
> Aside from that, your primary goal should be to get rid of the crash. Ever
> tried downgrading to a 1.3 JDK?
>
> ----- Original Message -----
> From: "Turner, John" <[EMAIL PROTECTED]>
> To: "'Tomcat Users List'" <[EMAIL PROTECTED]>
> Sent: Tuesday, February 25, 2003 6:16 PM
> Subject: RE: crontab problems
>
>
> >
> > No, I guess that would work.  It just seems to be needlessly complicated
> and
> > resource intensive.  You normally don't consider a program crashing as
> > normal behavior.  The point of a monitoring application is for it to
NEVER
> > crash, and continually check some other application.
> >
> > Think about it....cron launches your program to see if Tomcat is
started.
> > Well, Tomcat isn't.  That's a given, considering that the JVM just
> crashed.
> > A circle.  See?  Your application is Tomcat, not the JVM.
> >
> > My point is that if you can successfully retrieve output from Tomcat,
> > generated by either a servlet or a JSP, all is well.  Tomcat is happy,
the
> > JVM is happy, all is well.  If you can't, something is wrong, and you
have
> > to restart anyway.  Seems simpler to me, but I guess there will always
be
> > different ways to do things.
> >
> > Heck, if this happens alot, you'd probably just be better off profiling
> your
> > application, finding out WHY it happens (maybe something could be
> rewritten
> > or re-architected to avoid triggering those bugs), and possibly just
> > determining that a restart every other day or something is sufficient.
In
> > that case, just set up a cron job to run at 4 AM your time 3 times a
week
> > that restarts Tomcat, without even bothering to check status.
> >
> > The typcial goal for a monitoring application is to alert you that
> something
> > is wrong...not to treat something that goes wrong as a normal event.
> >
> > John
> >
> > > -----Original Message-----
> > > From: Ayhan Peker [mailto:[EMAIL PROTECTED]
> > > Sent: Tuesday, February 25, 2003 12:06 PM
> > > To: Tomcat Users List
> > > Subject: RE: crontab problems
> > >
> > >
> > > Am I right to think that if jvm crashes...Once writing to
> > > core file is
> > > finished, jvm can be restarted..(that is what we have been doing--jvm
> > > crashes, of course tomcat too)
> > > AND crontab say 5 min later..launches this java programme, which will
> > > restart tomcat..this is not a thread..just a java
> > > programme...that is the
> > > reason I am trying to launch it from crontab...
> > >
> > > When jvm crashes it writes its report..and goes away from the
> > > memory..You
> > > can still launch a java programme after this crash (like
> > > launching tomcat
> > > again after the crash)..
> > >
> > > ..
> > >
> > > --tomcat running
> > > --jvm crashes..
> > > --crontab launches my watcher (written in java)
> > > --my application checks if tomcat is running...and restarts
> > > is necessary..
> > > --if my programme is running at the time of crash..my
> > > programme crashes
> > > too...but 5 min later my programme is activated by crontab again..
> > >
> > >
> > > Am I missing something here?
> > >
> > > Take care..
> > >
> > > Ayhan
> > >
> > >
> > >
> > > At 10:12 AM 2/25/03 -0500, you wrote:
> > >
> > > >Well, if the JVM is "crashed", how can a program or
> > > application written in
> > > >Java help you manage Tomcat?  That was the point.
> > > >
> > > >John
> > > >
> > > > > -----Original Message-----
> > > > > From: Ayhan Peker [mailto:[EMAIL PROTECTED]
> > > > > Sent: Tuesday, February 25, 2003 9:43 AM
> > > > > To: Tomcat Users List
> > > > > Subject: RE: crontab problems
> > > > >
> > > > >
> > > > > I have no problems with tomcat...
> > > > >
> > > > > But sometimes under heavy load jvm 1.4 crashes...
> > > > > see the links:
> > > > >
> > > > > Ok this is the bug:
> > > > >
> > > http://developer.java.sun.com/developer/bugParade/bugs/4779653.html
> > > > > unfortunately it is closed, affects 1.4.1 and will not
> > > > > apparently be fixed.
> > > > > It oiccurs in large apps under load.on Linux and Solaris (
> > > > > and most likely
> > > > > Windows )
> > > > > It is related to / a copy of the following bug which
> > > > >
> > > http://developer.java.sun.com/developer/bugParade/bugs/4724356.html
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > what is the best suggestion?
> > > > >
> > > > > just trying to determine if tomcat is running..
> > > > > if not i will restart it ..
> > > > > (jvm just crashed last saturday night....I did not know
> > > > > anything until the
> > > > > sunday evening)..
> > > > >
> > > > >
> > > > > At 09:29 AM 2/25/03 -0500, you wrote:
> > > > >
> > > > > >Yes, Tomcat is generally very stable.  But: Trust, but verify. ;)
> > > > > >
> > > > > >John
> > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: Hannes Schmidt [mailto:[EMAIL PROTECTED]
> > > > > > > Sent: Tuesday, February 25, 2003 9:23 AM
> > > > > > > To: Tomcat Users List
> > > > > > > Subject: Re: crontab problems
> > > > > > >
> > > > > > >
> > > > > > > Yes, using wget is probably the second best solution. The
> > > > > > > best one is to
> > > > > > > find the reason why Tomcat crashes at all, since it generally
> > > > > > > is a stable
> > > > > > > and reliable product.
> > > > > > >
> > > > > > > Cron doesn't execute more than once a minute (at least mine
> > > > > > > doesn't) which
> > > > > > > still is quite often. 5 or 10 minutes would be ok too. But
> > > > > > > that's a matter
> > > > > > > of taste, really.
> > > > > > >
> > > > > > > ----- Original Message -----
> > > > > > > From: "Turner, John" <[EMAIL PROTECTED]>
> > > > > > > To: "'Tomcat Users List'" <[EMAIL PROTECTED]>
> > > > > > > Sent: Tuesday, February 25, 2003 3:00 PM
> > > > > > > Subject: RE: crontab problems
> > > > > > >
> > > > > > >
> > > > > > > >
> > > > > > > > Agreed...using a Java program to watch Tomcat seems a
> > > > > > > little circular.
> > > > > > > > Plus, I don't see any sort of delay or "sleep" in the
> > > > > poster's JAva
> > > > > > > > code...it looks like it just keeps hammering at Tomcat, as
> > > > > > > the cron job is
> > > > > > > > "* * * * *".  Creating all those Runtime objects over and
> > > > > > > over can't be
> > > > > > > > helping performance any.
> > > > > > > >
> > > > > > > > A simple shell script using wget would be fine...sure, you
> > > > > > > can watch the
> > > > > > > > output of "ps -ef", but that doesn't tell you if Tomcat
> > > > > is accepting
> > > > > > > > requests or not.  There could be an entry for Tomcat in the
> > > > > > > process table,
> > > > > > > > but Tomcat could be refusing requests.
> > > > > > > >
> > > > > > > > I just write a simple JSP page that outputs the contents of
> > > > > > > a variable,
> > > > > > > like
> > > > > > > > "***SUCCESS***" or something like that, then use wget to
> > > > > > > grab that page
> > > > > > > > every so often and check for the string in the output...if
> > > > > > > it's there,
> > > > > > > > things should be OK (there are no guarantees).  If it's
> > > > > > > not, you have a
> > > > > > > > problem.  This way, the JSP page is compiled and cached by
> > > > > > > Tomcat, it uses
> > > > > > > > very little memory, and doesn't bog down the server.
> > > > > > > >
> > > > > > > > There are plenty of other alternatives much more robust
> > > > > > > than a simple
> > > > > > > shell
> > > > > > > > script...you could use Netsaint/Nagios, Big Brother, and a
> > > > > > > whole bunch of
> > > > > > > > others.
> > > > > > > >
> > > > > > > > John
> > > > > > > >
> > > > > > > > > -----Original Message-----
> > > > > > > > > From: Hannes Schmidt
> > > [mailto:[EMAIL PROTECTED]
> > > > > > > > > Sent: Tuesday, February 25, 2003 6:29 AM
> > > > > > > > > To: Tomcat Users List
> > > > > > > > > Subject: Re: crontab problems
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Right, you might also just put
> > > > > > > > >
> > > > > > > > > JAVA_HOME=...
> > > > > > > > >
> > > > > > > > > at the beginning of your crontab.
> > > > > > > > >
> > > > > > > > > I assume you have good reasons to use a Java program to
> > > > > > > watch Tomcat.
> > > > > > > > > Personally, I would have written a shell script. If you
> > > > > > > > > really want to use
> > > > > > > > > Java, you might want to use a different, more reliable
> > > > > > > > > approach to detect
> > > > > > > > > (un)availability of Tomcat, something like
> > > > > > > > >
> > > > > > > > > import java.net.*;
> > > > > > > > > URL url = new URL( "http://localhost:8080/examples"; );
> > > > > > > > > URLConnection con = url.openConnection();
> > > > > > > > > con.setUseCaches( false );
> > > > > > > > > con.connect();
> > > > > > > > > if( con.getContentLength() > 0 ) {
> > > > > > > > >     // restart tomcat
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > But I just wrote this out of my head ...
> > > > > > > > >
> > > > > > > > > ----- Original Message -----
> > > > > > > > > From: "Ralph Einfeldt" <[EMAIL PROTECTED]>
> > > > > > > > > To: "Tomcat Users List" <[EMAIL PROTECTED]>
> > > > > > > > > Sent: Tuesday, February 25, 2003 10:43 AM
> > > > > > > > > Subject: RE: crontab problems
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > You have to make shure that your script retstart_tomcat
> > > > > > > > > sets and exports all needed environment variables before
> > > > > > > > > calling ./startup.sh:
> > > > > > > > >
> > > > > > > > > JAVA_HOME=/usr/local/java/jdk1.3.1
> > > > > > > > > CATALINA_HOME=<path to tomcat installation>
> > > > > > > > > CATALINA_BASE=<path to tomcat instance> or $CATALINA_HOME
> > > > > > > > > # JAVA_OPTS='-client -v'
> > > > > > > > >
> > > > > > > > > export JAVA_HOME CATALINA_HOME CATALINA_BASE JAVA_OPTS
> > > > > > > > > ./startup.sh
> > > > > > > > >
> > > > > > > > > > -----Original Message-----
> > > > > > > > > > From: Ayhan Peker [mailto:[EMAIL PROTECTED]
> > > > > > > > > > Sent: Tuesday, February 25, 2003 10:30 AM
> > > > > > > > > > To: [EMAIL PROTECTED]
> > > > > > > > > > Subject: crontab problems
> > > > > > > > > >
> > > > > > > > > > but the last two lines returns
> > > > > > > > > > /////////////////////////
> > > > > > > > > > The JAVA_HOME environment variable is not defined
> > > > > > > > > > message..
> > > > > > > > > > /////////////////////////
> > > > > > > > > > my retstart_tomcat scrip is
> > > > > > > > > > #!/bin/sh
> > > > > > > > > > cd /usr/local/tomcat/bin
> > > > > > > > > > ./startup.sh
> > > > > > > > >
> > > > > > > > >
> > > > > > >
> > > > >
> > > ---------------------------------------------------------------------
> > > > > > > > > To unsubscribe, e-mail:
> > > > > [EMAIL PROTECTED]
> > > > > > > > > For additional commands, e-mail:
> > > > > > > [EMAIL PROTECTED]
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > >
> > > > >
> > > ---------------------------------------------------------------------
> > > > > > > > > To unsubscribe, e-mail:
> > > > > [EMAIL PROTECTED]
> > > > > > > > > For additional commands, e-mail:
> > > > > > > [EMAIL PROTECTED]
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > >
> > > ---------------------------------------------------------------------
> > > > > > > > To unsubscribe, e-mail:
> > > > > [EMAIL PROTECTED]
> > > > > > > > For additional commands, e-mail:
> > > > > [EMAIL PROTECTED]
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > >
> > > ---------------------------------------------------------------------
> > > > > > > To unsubscribe, e-mail:
> > > [EMAIL PROTECTED]
> > > > > > > For additional commands, e-mail:
> > > > > [EMAIL PROTECTED]
> > > > > > >
> > > > > >
> > > > >
> > > >---------------------------------------------------------------------
> > > > > >To unsubscribe, e-mail:
> > > [EMAIL PROTECTED]
> > > > > >For additional commands, e-mail:
> > > [EMAIL PROTECTED]
> > > > >
> > > > >
> > > >
> > > >---------------------------------------------------------------------
> > > >To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > >For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to