Search in sources :

Example 1 with BaseThread

use of io.nuls.core.thread.BaseThread in project nuls by nuls-io.

the class TaskTable method remove.

public void remove(short moduleId) {
    Set<String> threadNameSet = MODULE_THREAD_MAP.get(moduleId);
    for (String name : threadNameSet) {
        BaseThread thread = THREAD_MAP.get(name);
        thread.interrupt();
        THREAD_MAP.remove(name);
    }
    MODULE_THREAD_MAP.remove(moduleId);
    Set<String> poolNameSet = MODULE_POOL_MAP.get(moduleId);
    for (String name : poolNameSet) {
        ThreadPoolExecutor pool = POOL_EXECUTOR_MAP.get(name);
        pool.shutdown();
        POOL_EXECUTOR_MAP.remove(name);
        POOL_THREAD_MAP.remove(name);
    }
    MODULE_POOL_MAP.remove(moduleId);
}
Also used : BaseThread(io.nuls.core.thread.BaseThread) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 2 with BaseThread

use of io.nuls.core.thread.BaseThread in project nuls by nuls-io.

the class NulsThreadFactory method newThread.

@Override
public final Thread newThread(Runnable r) {
    String threadName;
    if (threadNo.get() == 1) {
        threadNo.incrementAndGet();
        threadName = "[" + poolName + "]";
    } else {
        threadName = "[" + poolName + "-" + threadNo.getAndIncrement() + "]";
    }
    BaseThread newThread = new BaseThread(r, threadName);
    newThread.setModuleId(moduleId);
    newThread.setPoolName(poolName);
    newThread.setDaemon(true);
    if (newThread.getPriority() != Thread.NORM_PRIORITY) {
        newThread.setPriority(Thread.NORM_PRIORITY);
    }
    TaskManager.putThread(moduleId, poolName, threadName, newThread);
    return newThread;
}
Also used : BaseThread(io.nuls.core.thread.BaseThread)

Example 3 with BaseThread

use of io.nuls.core.thread.BaseThread in project nuls by nuls-io.

the class TaskManager method shutdownByModuleId.

public static void shutdownByModuleId(short moduleId) {
    List<ThreadPoolExecutor> poolList = THREAD_DATA_CACHE.getPoolList(moduleId);
    if (null != poolList) {
        for (ThreadPoolExecutor pool : poolList) {
            pool.shutdown();
        }
    }
    List<BaseThread> threadList = THREAD_DATA_CACHE.getThreadList(moduleId);
    if (null != threadList) {
        for (Thread thread : threadList) {
            if (thread.getState() == Thread.State.RUNNABLE) {
                thread.interrupt();
            }
        }
    }
    THREAD_DATA_CACHE.remove(moduleId);
}
Also used : BaseThread(io.nuls.core.thread.BaseThread) BaseThread(io.nuls.core.thread.BaseThread)

Example 4 with BaseThread

use of io.nuls.core.thread.BaseThread in project nuls by nuls-io.

the class PocConsensusModuleBootstrap method getInfo.

@Override
public String getInfo() {
    if (this.getStatus() == ModuleStatusEnum.UNINITIALIZED || this.getStatus() == ModuleStatusEnum.INITIALIZING) {
        return "";
    }
    StringBuilder str = new StringBuilder();
    str.append("module:[consensus]:\n");
    str.append("consensus status:");
    ConsensusStatusInfo statusInfo = consensusManager.getConsensusStatusInfo();
    if (null == statusInfo) {
        str.append(ConsensusStatusEnum.NOT_IN.getText());
    } else {
        str.append(ConsensusStatusEnum.getConsensusStatusByCode(statusInfo.getStatus()).getText());
    }
    str.append("\n");
    str.append("thread count:");
    List<BaseThread> threadList = TaskManager.getThreadList(this.getModuleId());
    if (null == threadList) {
        str.append(0);
    } else {
        str.append(threadList.size());
        for (BaseThread thread : threadList) {
            str.append("\n");
            str.append(thread.getName());
            str.append("{");
            str.append(thread.getPoolName());
            str.append("}");
        }
    }
    return str.toString();
}
Also used : BaseThread(io.nuls.core.thread.BaseThread) ConsensusStatusInfo(io.nuls.consensus.entity.ConsensusStatusInfo)

Example 5 with BaseThread

use of io.nuls.core.thread.BaseThread in project nuls by nuls-io.

the class TaskManager method stopThread.

public static void stopThread(short moduleId, String threadName) {
    BaseThread thread = THREAD_DATA_CACHE.getThread(threadName);
    if (thread.getState() == Thread.State.RUNNABLE) {
        thread.interrupt();
    }
    THREAD_DATA_CACHE.removeThread(moduleId, threadName);
}
Also used : BaseThread(io.nuls.core.thread.BaseThread)

Aggregations

BaseThread (io.nuls.core.thread.BaseThread)5 ConsensusStatusInfo (io.nuls.consensus.entity.ConsensusStatusInfo)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1