PpcProcessResult

@Data
@Accessors(chain = true)
public class PpcProcessResult {
    public static volatile int globalThreadStatus = DEFAULT_PPC_THREAD_STATUS;
    private String host;
    private Integer port;
    private Boolean isDebug;
    private Integer threadStatus;

    public synchronized static void setBusy(int tid){
        globalThreadStatus = globalThreadStatus | (1 << tid);
    }

    public synchronized static void setIdle(int tid){
        globalThreadStatus = globalThreadStatus & (~(1 << tid));
    }

    public synchronized static boolean isBusy(int tid){
        return (1 << tid) == ((1 << tid) & globalThreadStatus);
    }

    public synchronized static Integer getIdleTid(){
        if(globalThreadStatus >= BUSY_PPC_THREAD_STATUS){
            return null;
        }
        int tid = 1;
        //如果繁忙,则自增继续,直到取出status等于0
        int status = 1 << tid;
        while ((status & globalThreadStatus) != 0){
            status = status << 1;
            tid++;
        }
        return tid;
    }
}

 

posted @ 2020-10-12 23:21  牧之丨  阅读(159)  评论(0编辑  收藏  举报