private void createReceiverThread(final boolean exitOnEndOfStream) {
Thread receiverThread = new Thread("NativeSwing[" + pid + "] " + (isNativeSide()? "SWT": "Swing") + " Receiver") {
@Override
public void run() {
while(MessagingInterface.this.isAlive()) {
Message message = null;
try {
message = readMessageFromChannel();
} catch(Exception e) {
boolean isRespawned = false;
if(MessagingInterface.this.isAlive()) {
setAlive(false);
if(exitOnEndOfStream) {
terminate();
return;
}
e.printStackTrace();
try {
isRespawned = SWTNativeInterface.getInstance().notifyKilled();
} catch(Exception ex) {
ex.printStackTrace();
}
}
// Unlock all locked sync calls
synchronized(RECEIVER_LOCK) {
receivedMessageList.clear();
RECEIVER_LOCK.notify();
}
for(int instanceID: syncThreadRegistry.getInstanceIDs()) {
Object o = syncThreadRegistry.get(instanceID);
if(o instanceof ThreadLock) {
synchronized(o) {
o.notify();
}
}
}
if(isRespawned) {
SWTNativeInterface.getInstance().notifyRespawned();
}
}
if(message != null) {
if(!SWTNativeInterface.isMessageUI(message)) {
final Message message_ = message;
new Thread("NativeSwing[" + getPID() + "] Non-UI Message [" + SWTNativeInterface.getMessageID(message) + "] Executor") {
@Override
public void run() {
runMessage(message_);
}