здесь я хочу запустить мой весь список 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
}
Но мой код реагирует, так как размер первой очереди повторяется снова и сноватолько с этими элементами (if a.size()>channel where channel is b.size())
и не переходя к следующим элементам NOR Exit the while(looping)
.
может ли кто-нибудь solve/explain/describe
это?Спасибо ...