On Monday 09 February 2004 01:31, Florian I. Hayd wrote:
> Is there an easy or standard way how to implement/design components, which
> have to run the entire lifetime of the container and are supposed to exist
> only once?
I read between the lines that you know one of the answers...
In the component you probably do something like this;
public void initialize()
{
m_Thread = new Thread( someRunnable );
}
public void start()
{
m_Thread.start();
}
public void stop()
{
someRunnable.stopThread();
}
In the "someRunnable" (either being the component itself or another object);
public void run()
{
m_Running = true;
while( m_Running )
{
// Do whatever, possibly block on something
}
}
public void stopThread()
{
m_Running = false;
interrupt();
}
However, that is ONE straight forward solution.
If you on the other hand have a lot of threads that needs to be executed, you
could create a Thread Management component, that other component looks up via
the ServiceManager.lookup(), and pass it a Runnable object, or an object
implementing your own Worker interface.
And finally you could take a look at Excalibut-Thread, which does this (but I
haven't used it).
Niclas
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]