File tree Expand file tree Collapse file tree 2 files changed +8
-6
lines changed
app/src/main/java/com/lipisoft/toyshark Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change 2020import java .nio .ByteBuffer ;
2121import java .util .LinkedList ;
2222import java .util .Queue ;
23+ import java .util .concurrent .ConcurrentLinkedQueue ;
2324
2425import com .lipisoft .toyshark .network .ip .IPPacketFactory ;
2526import com .lipisoft .toyshark .network .ip .IPv4Header ;
@@ -45,7 +46,7 @@ public class SessionHandler {
4546
4647 private static final SessionHandler handler = new SessionHandler ();
4748
48- private Queue <Session > writableSessionsQueue = new LinkedList <>();
49+ private Queue <Session > writableSessionsQueue = new ConcurrentLinkedQueue <>();
4950 private IClientPacketWriter writer ;
5051 private SocketData packetData ;
5152
Original file line number Diff line number Diff line change 2020import java .nio .channels .UnresolvedAddressException ;
2121import java .nio .channels .UnsupportedAddressTypeException ;
2222import java .util .Iterator ;
23+ import java .util .Queue ;
2324import java .util .concurrent .BlockingQueue ;
2425import java .util .concurrent .LinkedBlockingQueue ;
2526import java .util .concurrent .ThreadPoolExecutor ;
@@ -112,16 +113,16 @@ private void runTask(){
112113 }
113114 }
114115
115- while (SessionHandler .getInstance ().getWritableSessions ().size () != 0 ) {
116- Session session = SessionHandler .getInstance ().getWritableSessions ().remove ();
116+ Queue <Session > sessions = SessionHandler .getInstance ().getWritableSessions ();
117117
118+ Session session = sessions .poll ();
119+ while (session != null ) {
118120 if (session .isConnected ()) {
119121 processPendingWrite (session );
120122 }
121123
122- if (shutdown ) {
123- break ;
124- }
124+ if (shutdown ) break ;
125+ session = sessions .poll ();
125126 }
126127 }
127128 }
You can’t perform that action at this time.
0 commit comments