Search in sources :

Example 1 with ChildThread

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

the class ThreadTag method doTerminate.

private void doTerminate() throws ApplicationException {
    // PageContextImpl mpc=(PageContextImpl)getMainPageContext(pc);
    // mpc.getThreadScope(nameAsString(false));
    Threads ts = ThreadTag.getThreadScope(pc, KeyImpl.init(nameAsString(false)), ThreadTag.LEVEL_CURRENT + ThreadTag.LEVEL_KIDS);
    if (ts == null)
        throw new ApplicationException("there is no thread running with the name [" + nameAsString(false) + "]");
    ChildThread ct = ts.getChildThread();
    if (ct.isAlive()) {
        ct.terminated();
        SystemUtil.stop(ct);
    }
}
Also used : Threads(lucee.runtime.type.scope.Threads) ChildThread(lucee.runtime.thread.ChildThread) ApplicationException(lucee.runtime.exp.ApplicationException)

Example 2 with ChildThread

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

the class ThreadTag method doJoin.

private void doJoin() throws ApplicationException {
    // PageContextImpl mpc=(PageContextImpl)getMainPageContext(pc);
    String[] names, all = null;
    Key name = name(false);
    if (name == null) {
        // mpc.getThreadScopeNames();
        all = names = ListUtil.toStringArray(ThreadTag.getThreadScopeNames(pc, ThreadTag.LEVEL_CURRENT + ThreadTag.LEVEL_KIDS));
    } else
        names = ListUtil.listToStringArray(name.getLowerString(), ',');
    ChildThread ct;
    Threads ts;
    long start = System.currentTimeMillis(), _timeout = timeout > 0 ? timeout : -1;
    for (int i = 0; i < names.length; i++) {
        if (StringUtil.isEmpty(names[i], true))
            continue;
        // PageContextImpl mpc=(PageContextImpl)getMainPageContext(pc);
        // mpc.getThreadScope(names[i]);
        ts = ThreadTag.getThreadScope(pc, KeyImpl.init(names[i]), ThreadTag.LEVEL_CURRENT + ThreadTag.LEVEL_KIDS);
        if (ts == null) {
            // mpc.getThreadScopeNames();
            if (all == null)
                all = ListUtil.toStringArray(ThreadTag.getThreadScopeNames(pc, ThreadTag.LEVEL_CURRENT + ThreadTag.LEVEL_KIDS));
            throw new ApplicationException("there is no thread running with the name [" + names[i] + "], only the following threads existing [" + ListUtil.arrayToList(all, ", ") + "]");
        }
        ct = ts.getChildThread();
        if (ct.isAlive()) {
            try {
                if (_timeout != -1)
                    ct.join(_timeout);
                else
                    ct.join();
            } catch (InterruptedException e) {
            }
        }
        if (_timeout != -1) {
            _timeout = _timeout - (System.currentTimeMillis() - start);
            if (_timeout < 1)
                break;
        }
    }
}
Also used : ChildThread(lucee.runtime.thread.ChildThread) Threads(lucee.runtime.type.scope.Threads) ApplicationException(lucee.runtime.exp.ApplicationException) Key(lucee.runtime.type.Collection.Key)

Aggregations

ApplicationException (lucee.runtime.exp.ApplicationException)2 ChildThread (lucee.runtime.thread.ChildThread)2 Threads (lucee.runtime.type.scope.Threads)2 Key (lucee.runtime.type.Collection.Key)1