Try { //System. Out. Println (" is the current Thread is: "+ Thread. CurrentThread (). The getName ()); Byte [] bytes=new byte [1024]. InputStream inp=socket. GetInputStream (); While (true) { Int read=inp. Read (bytes); if(read!=1) { System. The out. Println (Thread. CurrentThread (). The getName () + ":" + new String (bytes, 0, read)); } else {break; } } } the catch (Exception e) { //TODO: handle the exception e.printStackTrace(); } the finally { System. Out. Println (Thread. CurrentThread (). The getName () + "out"); Try { Socket. The close (); {} catch Exception (e2) //TODO: handle the exception E2. PrintStackTrace (); } } } }
Now the problem is, when I use the Linked/ArrayBlockingQueue, using the Telnet command 127.0.0.1 9527 has been only one thread, two Windows running this command will form the jam, must be closed first window to make the second window to send the information to send to the server, but using SynchronousQueue will, there is no this problem, why?
CodePudding user response:
I went to, how to modify my original meaning, not interrupt, too is a second window to send message to the console output, must be closed first window, the second window to send information to output, the most main is don't know why there is only one thread but using SynchronousQueue will, there is no this problem
CodePudding user response:
Release resources, SynchronousQueue will this should automatically release resources, other need to manually release
CodePudding user response:
There is nothing strange questions, appearing only no research problems, Change the core thread pool threads try,
CodePudding user response:
The thread pool execution order core thread - & gt; Waiting queue - & gt; Maximum thread, you 1 core number of threads, and use is LinkedBlockingQueue, of course, only one thread can normal operation, another thread tasks are exist in the queue, will not open a new thread to execute, and SynchronousQueue will this queue is special blocking queue, it actually not stored internally task, you can go to see the characteristics of SynchronousQueue will