gpt4 book ai didi

java - 为什么我的可运行接口(interface)循环我的队列继续这里

转载 作者:太空宇宙 更新时间:2023-11-04 09:38:09 25 4
gpt4 key购买 nike

在这里我想运行我的所有列表a大小有限 Queue b如果一个元素b.poll() (从队列中删除并使用)它再次添加一个。来自 List a 的元素等等......

我已经尝试了多种方法来停止循环。

public class BroadcastThreadInitializerProcessor implements Runnable {
@Autowired
private NetworkInterfaceServiceInterface networkInterfaceServiceInterface;

private volatile boolean running = true;
private volatile boolean paused = false;

private VoiceBroadcast voiceBroadcast =null;

List<ExcelDatas> a = null;

public BroadcastThreadInitializerProcessor(VoiceBroadcast voiceBroadcast, UploadExcel uploadExcel ) {
this.voiceBroadcast=voiceBroadcast;
this.a = uploadExcel.getExcelDatas();
}

@Override
public void run() {
while (running){
synchronized (a) {
if (!running) {
break;
}
if (paused) {
try {
a.wait();
} catch (InterruptedException ex) {
break;
}
if (!running) { // running might have changed since we paused
break;
}
}
}//syncronized stop

// Broadcasting code START here...
int channels = Integer.parseInt(voiceBroadcast.getChannel());
try {
Queue<ExcelDatas> b = null;
int aIndex = 0;
if(a.size()> channels){ //load elements in Queue
b = new LinkedList<>();
for (int i = 0; i < channels ; i++) {
b.add(a.get(aIndex));
aIndex++;
}
}else {
b = new LinkedList<>(a); //load all elements
}
Client client = new Client();
client.connect("", , "", 10);
client.setEventSubscriptions( "", "" );
boolean looping = true;

while (looping) { //looping while

if (paused) {
a.wait();
}
if (!running) { looping=false; break;} // break when all call are completed
if (b.isEmpty()) { running=false; break;} // break when all call are completed
EslMessage chan = client.sendSyncApiCommand("show channels count","");
int usedChannel = Integer.parseInt(Arrays.asList(chan.getBodyLines().toString().replaceAll("[^0-9]+"," ").trim().split(" ")).get(0));
if(usedChannel<(channels-1)) {
System.err.println("Used Channels "+usedChannel +" <--Total Channels"+channels);
ExcelDatas frontValue = b.poll(); // get queue's first element and remove it
String uuid = UUID.randomUUID().toString();

if(frontValue.getContact().length()>=10) {
client.sendSyncApiCommand("",""); //for calling
System.err.println("Callling on "+frontValue.getContact()+" By clip number:-"+voiceBroadcast.getClip()+" with UUID:-"+uuid);
}//if for Contact number

//call Processs Stop
if(a.size()> channels){
if (aIndex < a.size()) {
b.add(a.get(aIndex++)); //Add of New Node in Queue
}//inner if node set
}//if upper
//for close all loops if b is empty
if(b.isEmpty()) {
System.err.println("b is empty");
running = false;
looping=false;
break;
}//if

Thread.sleep(700);
}//upper if ports check

}//Stop looping while loop

looping=false;
running = false;
client.close();
}catch (Exception e) {

}

// Broadcasting code STOP here...
}//while loop

}//run() method STOP


// Actions methods Start
public void terminate() {
running = false;
}

public void pause() {
paused = true;
}

public void resume() {
synchronized (a) {
paused = false;
a.notifyAll(); // Unblocks thread
}
}
//Action Methods STOP
}

但是我的代码使用react,因为第一个队列大小仅使用这些元素一次又一次地重复运行 (if a.size()>channel where channel is b.size())它不会进入下一个元素 NOR Exit the while(looping) .

任何人都可以吗solve/explain/describe它 ?谢谢...

最佳答案

这里我只是改变了,

private static  BlockingQueue<ExcelDatas> queue = null;
......
......
queue = new ArrayBlockingQueue<>(channels);
.......
.......
ExcelDatas frontValue = queue.take();

它解决了我的问题,谢谢@AntoineMarques。

关于java - 为什么我的可运行接口(interface)循环我的队列继续这里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56251672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com