Petri Salmi wrote:
Hi!

I think this is more like Avalon Users stuff, so I am directing the response there.


On 12. maaliskuuta 2003 22:39, Filip Defoort [mailto:[EMAIL PROTECTED] wrote:


Hi,

Couple of questions reg. the CommandQueue (in same spirit of the ones reg. the Cache):

1/ is it possible to "manage"/"view" a Queue, that is can a Queue be
queried to see which commands are running + can running commands be interrupted (I know this is a though one, but I still need some
way of interrupting long operations, the well-known dough-experience)


AFAIK, the commands are run in for as long as it takes them to complete.
I would suggest that you wrap your long running commands within a monitoring instance that can interrupt the process if required.


One way you can have a command *act* like a long running command is
to use a RepeatedCommand.  For things like monitoring resources or
doing periodic background checks, it is indispensible.

It doesn't burn a thread for the life of an application, but it does
its function.  90% of threads that I see written in server apps are
to sit around and wait, monitoring some event.  They spend most of
their life waiting, and doing nothing.  Why not allow another action
to happen using the same thread?

As to a command that simply takes a long time, you can use the
RepeatedCommand approach again--this time to break your task
into chunks:

class MyChunkedCommand extends RepeatedCommand
{
    int m_step = 0;
    int m_numSteps = 4;

    public long numberOfRepeats() { return m_numSteps; }
    // ... add in the other timer related methods

    public void execute() throws Exception
    {
        switch(m_step)
        {
            case 0:
                executeStep1();
                break;

             case 1:
                executeStep2();
                break;

            case 2:
                executeStep3();
                break;

             case 3:
                executeStep4();
                break;

             default:
                 throw Exception("We should never get here!");
                 break;
        }

        m_step++;
    }

    // ... add in the implementations of steps 1-4
}

It works well if you have a long running task that is not
required to finish ASAP.  It would work better if Java had
support for continuations--which would take out the switch
because the continuation would allow the language to remember
where the application was...  But that's just dreaming for
now.


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



Reply via email to