kill thread when wait() fires InterruptedException

Rather than just dropping it and going back to a wait that will likely
last forever. I *think* wait() throwing that exception means the
thread's being killed, in which case the exception should be thrown up
to the containing loop that will then exit.
This commit is contained in:
Eric House 2018-12-11 06:57:59 -08:00
parent f2322d7e81
commit 4f8f14c83b

View file

@ -999,16 +999,11 @@ public class RelayService extends JobIntentService
} }
} }
private RelayService getService() private RelayService getService() throws InterruptedException
{ {
synchronized ( mServiceHolder ) { synchronized ( mServiceHolder ) {
while ( null == mServiceHolder[0] ) { while ( null == mServiceHolder[0] ) {
try {
mServiceHolder.wait(); mServiceHolder.wait();
} catch (InterruptedException ie) {
Log.e( TAG, "wait() threw: %s", ie.getMessage() );
// Assert.assertFalse( BuildConfig.DEBUG );
}
} }
return mServiceHolder[0]; return mServiceHolder[0];
} }
@ -1018,7 +1013,7 @@ public class RelayService extends JobIntentService
{ {
m_UDPReadThread = new Thread( null, new Runnable() { m_UDPReadThread = new Thread( null, new Runnable() {
public void run() { public void run() {
try {
connectSocket(); // block until this is done connectSocket(); // block until this is done
startWriteThread(); startWriteThread();
@ -1038,6 +1033,11 @@ public class RelayService extends JobIntentService
break; break;
} }
} }
} catch ( InterruptedException ie ) {
Log.d( TAG, "exiting on interrupt: %s",
ie.getMessage() );
}
Log.i( TAG, "read thread exiting" ); Log.i( TAG, "read thread exiting" );
} }
}, getClass().getName() ); }, getClass().getName() );
@ -1054,7 +1054,7 @@ public class RelayService extends JobIntentService
m_queue.add( packet ); m_queue.add( packet );
} }
private void connectSocket() private void connectSocket() throws InterruptedException
{ {
if ( null == m_UDPSocket ) { if ( null == m_UDPSocket ) {
int port; int port;
@ -1109,10 +1109,6 @@ public class RelayService extends JobIntentService
dataListUDP.add( outData ); dataListUDP.add( outData );
} }
} }
} catch ( InterruptedException ie ) {
Log.w( TAG, "write thread killed" );
break;
}
sendViaWeb( dataListWeb ); sendViaWeb( dataListWeb );
sendViaUDP( dataListUDP ); sendViaUDP( dataListUDP );
@ -1122,6 +1118,10 @@ public class RelayService extends JobIntentService
runUDPAckTimer(); runUDPAckTimer();
ConnStatusHandler.showSuccessOut(); ConnStatusHandler.showSuccessOut();
} catch ( InterruptedException ie ) {
Log.w( TAG, "write thread killed" );
break;
}
} }
Log.i( TAG, "write thread killing read thread" ); Log.i( TAG, "write thread killing read thread" );
@ -1140,7 +1140,7 @@ public class RelayService extends JobIntentService
m_UDPWriteThread.start(); m_UDPWriteThread.start();
} }
private int sendViaWeb( List<PacketData> packets ) private int sendViaWeb( List<PacketData> packets ) throws InterruptedException
{ {
int sentLen = 0; int sentLen = 0;
if ( packets.size() > 0 ) { if ( packets.size() > 0 ) {
@ -1196,7 +1196,7 @@ public class RelayService extends JobIntentService
return sentLen; return sentLen;
} }
private int sendViaUDP( List<PacketData> packets ) private int sendViaUDP( List<PacketData> packets ) throws InterruptedException
{ {
int sentLen = 0; int sentLen = 0;