I am facing this problem where one thread keeps adding packets which it receives from the network to linkedlist. And the other thread retrieves it from the linked list.
The below is the code of the Thread which keeps receiving the packets and add's them to list.
private class ReceivingPacket implements Runnable
{
public void run()
{
packet =new DatagramPacket(new byte[8210],8210);
try {
while(true)
{
socket.receive(packet);
list.add(packet);
}
The below code gets packet from the list and processes them. packet2 is a DatagramPacket
if(list.size()>0)
{
packet2=list.getFirst();//.................................1
System.out.println(packet2);
buf = packet2.getData();...................................2
System.out.println(list.size()+ " ");
jpacket = new Jpacket(buf);
list.remove();
break;
}
else
{....
Now i have observed that [1] works fine. But after [2] the code doesnt move forward.
even if i print packet2.getLength(). The code doesnt run and the Thread doesnt proceed.
Pl help