ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hal Hildebrand \(web\)" <Hal.Hildebr...@hellblazer.com>
Subject Re: Starting a Java application in the background.
Date Tue, 02 Jul 2002 16:48:13 GMT
Do you have a simplified example of the Ant script you're using?  If you
are spawning processes from your own code, you'll have to use shutdown
hooks to kill them when the parent dies:

final Process proc = Runtime.getRuntime().exec(cmd, env);
Runtime.getRuntime().addShutdownHook(
    new Thread(
        new Runnable() {
            public void run() {
                proc.destroy();
            }
        }));

Calling destroy on a process already destroyed is a no-op.  You can use
Runtime.getRuntime().removeShutdownHook() to remove the thread after
things have completed normally.

In beta3, the only problem with exec is the handling of the
InterruptedException in Execute.  The method  waitFor() will silently
ignore the exception, and the exec() method thinks things have
terminated normally and will remove the shutdown hook that would kill
the spawned process.  A quick fix is:

    protected void waitFor(Process process) {
        try {
            process.waitFor();
            setExitValue(process.exitValue());
        } catch (InterruptedException e) {
            process.destroy();
        }
    }

If you are seeing processes still hanging around from Execute, rather
than from your own program, this might be the culprit.

Hope this helps...

----- Original Message -----
From: "Ric Searle" <ric@dialogue.co.uk>

> This is:
>
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
>
> with
>
> Apache Ant version 1.5Beta3 compiled on June 22 2002
>
> Hope this helps,
>
> Ric
>
> On Tuesday, July 2, 2002, at 04:13  pm, Hal Hildebrand ((web)) wrote:
>
> > Is this under JDK 1.3 or 1.4?
> >
> > Ant 1.5 beta 2 fixed this to kill all spawned processes when the
parent
> > is terminated.
> >
> > Seems like the JDK did something different in their process spawning
in
> > JDK 1.3 that was different from previous versions.  Spawned
processes
> > are not tied to the parent's lifetime in this version and above.
> >
> > ----- Original Message -----
> > From: "Ric Searle" <ric@dialogue.co.uk>
> >
> >> You are mixing up the children and parents relations of the two. A
> > java
> >> task is a child of the ant process. Killing the ant process will
kill
> >> its children as well.
> >
> > That's what I would have thought, but it doesn't.  The java task
that
> > ant started carries on even when all of the ant processes have died.
> >
> > Ric
> >
> > On Monday, July 1, 2002, at 06:02  pm, Thomas Zander wrote:
> >
> >> You are mixing up the children and parents relations of the two. A
> > java
> >> task is a child of the ant process. Killing the ant process will
kill
> >> its children as well.
> >> With the java process still living after ant died the children died
> > and
> >> the parent still lives.
> >>
> >> There is a way on linux to 'detach' a child from its parent. No
idea
> > if
> >> Java supports that.
> >>
> >> So; like Steve said; its quite hard to write :)
> >>
> >>
> >> from On Mon, Jul 01, 2002 at 11:41:01AM +0100, Ric Searle wrote:
> >>> Thanks. It seems like a nice feature that ant could do with.
> >>>
> >>> I like the idea of saying to our support department, "Get version
> > x.x
> >>> from CVS, and then just type 'ant' to build and run it.".
> >>>
> >>> Here's a thought: Killing any of the ant processes (on Linux at
> >> least)
> >>> kills all of the ant processes, but leaves the Java task that ant
> >>> started running. This is the effect I want, so is there a way of
> >> getting
> >>> ant to kill itself at the end of the build?
> >>>
> >>> Regards,
> >>>
> >>> Ric Searle
> >>>
> >>>
> >>> On Friday, June 28, 2002, at 05:27 pm, Steve Loughran wrote:
> >>>
> >>>>
> >>>>
> >>>>> That's by design - usually java processes are part of the build,
> > and
> >>>>> the
> >>>> build won't continue until the process has terminated. Ant will
> >>>> redirect the
> >>>> process's output/error streams to the build log, too.
> >>>>
> >>>>> It shouldn't be *too* hard to write some kind of "background"
flag
> >> in
> >>>>> the
> >>>> Java task, but I suspect you'd need to find >someone who truly
> >>>> understands
> >>>> that code first.
> >>>>
> >>>> There are some patche in bugzilla.
> >>>>
> >>>> It is hard to write, at least in a cross-platform way
> >>
> >> --
> >> Thomas Zander
> >> zander@planescape.com
> >> We are what we pretend
> >> to be
> >>
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <mailto:ant-user-unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail:
> > <mailto:ant-user-help@jakarta.apache.org>
> >
> >
> >
> >
> >
> > --
> > To unsubscribe, e-mail:   <mailto:ant-user-
> > unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail: <mailto:ant-user-
> > help@jakarta.apache.org>
> >
>
>
> --
> To unsubscribe, e-mail:
<mailto:ant-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:ant-user-help@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message