On Tuesday 24 February 2004 03:35, Florian I. Hayd wrote:
> I've got two questions, which might be dependend. I'm developing an
> application which checks different sources for messages and works with
> them. There is one component, which is started and which starts and stopps
> all other services and does the coordination. Basically, this component has
> to run all the time. If I use a while(true) or a while (boolean)
> statements, it locks me out from using the Ctrl+C to stop the component.
> (or is there some kind of a default timelimit?). How do I design my
> component/application to have one active coordinator/controller component
> which dispatches, starts and stopps other components? Do I have to use a
> new Thread. But then, after the main thread is done, it stopps. Maybe I
> missed the point. Can someone please explain me?
You MUST create your own thread. If you don't, Merlin will try to interrupt
your exection, and if that fails, abort the whole JVM, as it will think the
deployment has failed. (This started in Merlin 3.2. In earlier versions you
had other behaviour, still not correct ones.)
Why your app stops when the initial thread is done is something else. You must
be doing something wrong.
Recommended pattern;
public class MyComp
implements Startable, Initializable
{
private Thread m_Thread;
public void initialize()
{
m_Thread = new Thread( this ); //or other Runnable
}
public void start()
{
m_Thread.start();
}
public void stop()
{
m_Thread.interrupt(); // make sure threads are interruptable.
}
}
Double-check and come back if there are problems.
> How can I influence the order of
> activation/initialization of components?
Merlin determines the order by looking at Dependencies. If CompA DependsOn
CompB, Merlin will ensure that CompB is instantiated/initailiazed/serviced
before CompA. And on shutdown in the reverse order.
As for your DB client/server dilemma, you SHOULD write code that doesn't need
the server to be active and code that can recover from disconnections and
network problems without crashing.
If that is too much trouble now, then declare a dependency in the client
component, that it depends on the server component.
Niclas
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]