I need your help.
I got 2 JAVA classes. In one class there is a FIFO list/queue, both classes have to access this list concurrent. The list is in class1. Class1 uses the addElementToEndOfQueue. Class2 uses getValueOfQueue to get und remove the head of the queue.
public static synchronized String getValueOfQueue(){
return queueSend.poll();
}
public synchronized boolean addValueToQueue(String s){
Boolean blnReturn = queueSend.offer(s);
class2.interrupt();
return blnReturn;
}
Class2 tries and takes the head value of the queue, if the queue is null than strValue is null and the thread should wait till he is interrupted bei addValueToQueue:
while(true){
String strValue = class1.getValueOfQueue();
if (strValue == null) {
try {
wait();}
catch (InterruptedException e) {
continue;}
// do things
}
My problem is now that if have to wait/sleep in the while loop (to simulate a delay). If i use sleep or wait than it could happen that addValueToQueue interrupts me and I don't want that. I want the programm to wait the given time and not be interrupted. How can I do this? Or should I use a completely other approach as I am using right now? Thanks for your help!