I am trying to run some multithreading in Java using LinkedBlockingQueue, but it seems the behavior is not as I am expecting. My main method is starting a new thread, who simply checks if the toSend queue is full. If it is not, then it simply waits till it is. In this context, I never add anything to it, but I still expect my main method to continue to the line after the creation of the thread and print the following line:
System.out.println("Multithreading continues as expected");
Eventually, my main method goes on to actually create another thread which will put packets into the toSend. However, it is not able to proceed past the creation of the thread. Any help would be greatly appreciated!!
public static void main(String[] args) {
System.out.println("we are here);
SendThread s = new SendThread();
s.run();
System.out.println("Multithreading continues as expected");
}
LinkedBlockingQueue<Packet> toSend = new LinkedBlockingQueue<>();
public static class SendThread extends Thread {
public void run() {
System.out.println("Send Thread now active");
while(true) {
toSend.take();
System.out.println("packet taken");
}
}
}