here is my thread code
Thread decode = new Thread(new Runnable() {
@Override
public void run() {
// System.out.println("decode thread started");
synchronized (queueLock) {
while (true) {
if (!queue.isEmpty()) {
System.out.println(decoding());
}
}
}
}
});
here is my member field
private PriorityQueue<String> queue = new PriorityQueue<String>();
private Object queueLock = new Object();
and here is my method
public Character decoding() {
String code = queue.poll();
Character chr;
Character[][] key = kG.getKey();
String binary = null;
Character startingCharacter = code.charAt(0);
int iK = 0;
int ascii;
//System.out.println(code); when i use this other threads do not start also
for (int i = 0; i < KeyGenerator.getIr(); i++)
if (startingCharacter == key[i][0])
iK = i;
for (int j = 0; j < KeyGenerator.getJr(); j++) {
if (code.contains(String.valueOf(key[iK][j])))
binary = binary + "1";
else
binary = binary + "0";
}
ascii = Integer.parseInt(binary, 2);
chr = (char) (ascii + 'a');
return chr;
}
the prioritqueue is using by another thread but i made it synchronized by using a queueLock object
.
the method decoding
is not working in docode thread
!!!