@@ -146,6 +146,14 @@ protected void connect(final SocketChannel channel) throws Exception {
146
146
} finally {
147
147
bufferLock .unlock ();
148
148
}
149
+
150
+ channel .configureBlocking (false );
151
+ this .channel = channel ;
152
+
153
+ startThreads (channel .getRemoteAddress ().toString ());
154
+ }
155
+
156
+ protected void startThreads (String threadName ) throws IOException , InterruptedException {
149
157
final CountDownLatch init = new CountDownLatch (2 );
150
158
reader = new Thread (new Runnable () {
151
159
@ Override
@@ -162,18 +170,20 @@ public void run() {
162
170
}
163
171
});
164
172
165
- channel .configureBlocking (false );
166
- this .channel = channel ;
167
173
168
- reader .setName ("Tarantool " + channel .getRemoteAddress ().toString () + " reader" );
169
- writer .setName ("Tarantool " + channel .getRemoteAddress ().toString () + " writer" );
170
- writer .setPriority (config .writerThreadPriority );
171
- reader .setPriority (config .readerThreadPriority );
174
+ configureThreads (threadName );
172
175
reader .start ();
173
176
writer .start ();
174
177
init .await ();
175
178
}
176
179
180
+ protected void configureThreads (String threadName ) {
181
+ reader .setName ("Tarantool " + threadName + " reader" );
182
+ writer .setName ("Tarantool " + threadName + " writer" );
183
+ writer .setPriority (config .writerThreadPriority );
184
+ reader .setPriority (config .readerThreadPriority );
185
+ }
186
+
177
187
178
188
protected void auth (String username , final String password ) throws Exception {
179
189
final MessageDigest sha1 = MessageDigest .getInstance ("SHA-1" );
@@ -324,7 +334,7 @@ protected void writeFully(SocketChannel channel, ByteBuffer buffer) throws IOExc
324
334
325
335
protected void readThread () {
326
336
try {
327
- while (!Thread .interrupted ()) {
337
+ while (!Thread .currentThread (). isInterrupted ()) {
328
338
try {
329
339
long code ;
330
340
readPacket ();
@@ -358,13 +368,13 @@ protected void readPacket() throws IOException {
358
368
359
369
protected void writeThread () {
360
370
writerBuffer .clear ();
361
- while (!Thread .interrupted ()) {
371
+ while (!Thread .currentThread (). isInterrupted ()) {
362
372
try {
363
373
bufferLock .lock ();
364
- if (sharedBuffer .position () == 0 ) {
365
- bufferNotEmpty .await ();
366
- }
367
374
try {
375
+ while (sharedBuffer .position () == 0 ) {
376
+ bufferNotEmpty .await ();
377
+ }
368
378
sharedBuffer .flip ();
369
379
writerBuffer .put (sharedBuffer );
370
380
sharedBuffer .clear ();
0 commit comments