Task 生成排队人数任务线程

package main.com.lift;

import com.google.common.collect.Lists;

import java.util.List;
import java.util.Queue;
import java.util.concurrent.Callable;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.LinkedBlockingQueue;

public class Task implements Callable> {
    List loucengList;
    CyclicBarrier cyclicBarrier;
    LinkedBlockingQueue queue;
    public Task(CyclicBarrier cyclicBarrier,List loucengList,LinkedBlockingQueue queue){
        this.cyclicBarrier=cyclicBarrier;
        this.loucengList=loucengList;
        this.queue=queue;
    }
    @Override
    public Queue call() throws Exception {
        Queue childQueue= Lists.newLinkedList();
        try{
            cyclicBarrier.await();
            do{
                synchronized (queue){
                    if(queue.size()>0){
                        int a=queue.poll();
                        if(loucengList.toString().contains(a+"")){
                            childQueue.offer(a);
                        }else {
                            queue.offer(a);
                        }
                    }
                }
                System.out.println(","+queue.size());
            }while (queue.size()>0);
        }catch (Exception e){
            e.printStackTrace();
        }
        return childQueue;
    }
}

 

你可能感兴趣的:(电梯最优化组合项目)