@@ -109,38 +109,45 @@ public static void main(String args[]) throws Exception {
109
109
Socket s2 = ss .accept ();
110
110
111
111
// setup conditions for untransmitted data and lengthy
112
- // linger interval
113
- s1 .setSendBufferSize (128 *1024 );
112
+ // linger interval
113
+ s1 .setSendBufferSize (128 *1024 );
114
114
s1 .setSoLinger (true , 30 );
115
115
s2 .setReceiveBufferSize (1 *1024 );
116
116
117
117
// start sender
118
- Thread thr = new Thread (new Sender (s1 ));
119
- thr .start ();
118
+ Thread senderThread = new Thread (new Sender (s1 ));
119
+ senderThread .start ();
120
120
121
121
// other thread that will connect after 5 seconds.
122
- Other other = new Other (ss .getLocalPort (), 5000 );
123
- thr = new Thread (other );
124
- thr .start ();
122
+ Other other = new Other (ss .getLocalPort (), 5000 );
123
+ Thread otherThread = new Thread (other );
124
+ otherThread .start ();
125
125
126
126
// give sender time to queue the data
127
- System .out .println ("Main sleep 1000" );
128
- Thread .sleep (1000 );
129
- System .out .println ("Main continue" );
127
+ System .out .println ("Main sleep 1000" );
128
+ Thread .sleep (1000 );
129
+ System .out .println ("Main continue" );
130
130
131
131
// close the socket asynchronously
132
- (new Thread (new Closer (s1 ))).start ();
132
+ Thread closerThread = new Thread (new Closer (s1 ));
133
+ closerThread .start ();
133
134
134
- System .out .println ("Main sleep 15000" );
135
+ System .out .println ("Main sleep 15000" );
135
136
// give other time to run
136
- Thread .sleep (15000 );
137
- System .out .println ("Main closing serversocket" );
137
+ Thread .sleep (15000 );
138
+ System .out .println ("Main closing serversocket" );
138
139
139
140
ss .close ();
140
141
// check that other is done
141
- if (!other .connected ()) {
142
+ if (!other .connected ()) {
142
143
throw new RuntimeException ("Other thread is blocked" );
143
144
}
145
+
146
+ // await termination of all test related threads
147
+ senderThread .join (60_000 );
148
+ otherThread .join (60_000 );
149
+ closerThread .join (60_000 );
150
+
144
151
System .out .println ("Main ends" );
145
152
}
146
153
}
0 commit comments