Search in sources :

Example 1 with ThreadsImpl

use of lucee.runtime.thread.ThreadsImpl in project Lucee by lucee.

the class ThreadTag method register.

public void register(Page currentPage, int threadIndex) throws PageException {
    if (ACTION_RUN != action)
        return;
    Key name = name(true);
    try {
        // pc.getThreadScope(name);
        Threads ts = ThreadTag.getThreadScope(pc, name, ThreadTag.LEVEL_ALL);
        if (type == TYPE_DAEMON) {
            if (ts != null)
                throw new ApplicationException("could not create a thread with the name [" + name.getString() + "]. name must be unique within a request");
            ChildThreadImpl ct = new ChildThreadImpl((PageContextImpl) pc, currentPage, name.getString(), threadIndex, attrs, false);
            pc.setThreadScope(name, new ThreadsImpl(ct));
            ct.setPriority(priority);
            ct.setDaemon(false);
            ct.start();
        } else {
            ChildThreadImpl ct = new ChildThreadImpl((PageContextImpl) pc, currentPage, name.getString(), threadIndex, attrs, true);
            ct.setPriority(priority);
            ((ConfigImpl) pc.getConfig()).getSpoolerEngine().add(new ChildSpoolerTask(ct, plans));
        }
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw Caster.toPageException(t);
    } finally {
        // this method is not called from template when type is run, a call from template is to early,
        ((PageContextImpl) pc).reuse(this);
    }
}
Also used : Threads(lucee.runtime.type.scope.Threads) ThreadsImpl(lucee.runtime.thread.ThreadsImpl) ChildThreadImpl(lucee.runtime.thread.ChildThreadImpl) ApplicationException(lucee.runtime.exp.ApplicationException) ChildSpoolerTask(lucee.runtime.thread.ChildSpoolerTask) PageContextImpl(lucee.runtime.PageContextImpl) Key(lucee.runtime.type.Collection.Key)

Aggregations

PageContextImpl (lucee.runtime.PageContextImpl)1 ApplicationException (lucee.runtime.exp.ApplicationException)1 ChildSpoolerTask (lucee.runtime.thread.ChildSpoolerTask)1 ChildThreadImpl (lucee.runtime.thread.ChildThreadImpl)1 ThreadsImpl (lucee.runtime.thread.ThreadsImpl)1 Key (lucee.runtime.type.Collection.Key)1 Threads (lucee.runtime.type.scope.Threads)1