avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Berin Loritsch" <blorit...@apache.org>
Subject RE: [A5] Activity Package
Date Mon, 17 Jun 2002 13:32:31 GMT
> From: Peter Donald [mailto:peter@apache.org] 
> 
> At 06:01 PM 6/15/2002 +0200, you wrote:
> >>2) We have determined that start() and stop() apply to the 
> same concern
> >>    of an active component.  We should explicitly state that the 
> >>Startable
> >>    interface is designed to let an active component know 
> when they can
> >>    start background execution threads and when to stop them safely.
> >
> >I disagree.
> >
> >As I have already written, starting something doesn't mean 
> that I need 
> >to
> >stop it. It could just stop by itself. In fact the stop() method of 
> >threads has been deprecated long time ago!
> 
> Thread.stop() was deprecated because it is impossible to 
> isolate state 
> between threads and thus perform cleanups on stop(). In 
> JDK1.5 the isolate 
> classes will most likely have some form of stop() method.


Also, PLEASE.  Avalon's Startable.stop() and JDK's Thread.stop()
are two totally different things.  DO NOT CONFUSE THEM!

A typical way to safely enforce a stop() in Avalon is this:


class StoppableComponent implements Stoppable, Runnable
{
    private Thread m_thread;
    private volitile boolean m_isRunning; // changes are atomic now

    public void start()
    {
        m_thread = new Thread(this);
        m_thread.start();
    }

    public void run()
    {
        m_isRunning = true;

        while(m_isRunning)
        {
            //  Do action

            try
            {
                m_thread.sleep(1000); // sleep for a second
            }
            catch (InterruptedException ie) {}
        }
    }

    public void stop()
    {
        m_isRunning = false;
        m_thread.join();
        m_thread = null;
    }
}

That has nothing to do with calling Thread.stop()

DO NOT confuse the two.


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


Mime
View raw message