BAEL-4297: fixed unsynchronized classes naming, added slf4j logging
This commit is contained in:
parent
9d24bc1598
commit
3fd8926145
@ -1,6 +1,10 @@
|
|||||||
package com.baeldung.exceptions.illegalmonitorstate;
|
package com.baeldung.exceptions.illegalmonitorstate;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class SynchronizedReceiver implements Runnable {
|
public class SynchronizedReceiver implements Runnable {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(SynchronizedReceiver.class);
|
||||||
private final Data data;
|
private final Data data;
|
||||||
private String message;
|
private String message;
|
||||||
private boolean illegalMonitorStateExceptionOccurred;
|
private boolean illegalMonitorStateExceptionOccurred;
|
||||||
@ -16,10 +20,10 @@ public class SynchronizedReceiver implements Runnable {
|
|||||||
data.wait();
|
data.wait();
|
||||||
this.message = data.receive();
|
this.message = data.receive();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
log.error("thread was interrupted", e);
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
} catch (IllegalMonitorStateException e) {
|
} catch (IllegalMonitorStateException e) {
|
||||||
e.printStackTrace();
|
log.error("illegal monitor state exception occurred", e);
|
||||||
illegalMonitorStateExceptionOccurred = true;
|
illegalMonitorStateExceptionOccurred = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package com.baeldung.exceptions.illegalmonitorstate;
|
package com.baeldung.exceptions.illegalmonitorstate;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class SynchronizedSender implements Runnable {
|
public class SynchronizedSender implements Runnable {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(SynchronizedSender.class);
|
||||||
private final Data data;
|
private final Data data;
|
||||||
private boolean illegalMonitorStateExceptionOccurred;
|
private boolean illegalMonitorStateExceptionOccurred;
|
||||||
|
|
||||||
@ -18,10 +22,10 @@ public class SynchronizedSender implements Runnable {
|
|||||||
|
|
||||||
data.notifyAll();
|
data.notifyAll();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
log.error("thread was interrupted", e);
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
} catch (IllegalMonitorStateException e) {
|
} catch (IllegalMonitorStateException e) {
|
||||||
e.printStackTrace();
|
log.error("illegal monitor state exception occurred", e);
|
||||||
illegalMonitorStateExceptionOccurred = true;
|
illegalMonitorStateExceptionOccurred = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package com.baeldung.exceptions.illegalmonitorstate;
|
package com.baeldung.exceptions.illegalmonitorstate;
|
||||||
|
|
||||||
public class UnSynchronizedReceiver implements Runnable {
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class UnsynchronizedReceiver implements Runnable {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(UnsynchronizedReceiver.class);
|
||||||
private final Data data;
|
private final Data data;
|
||||||
private String message;
|
private String message;
|
||||||
private boolean illegalMonitorStateExceptionOccurred;
|
private boolean illegalMonitorStateExceptionOccurred;
|
||||||
|
|
||||||
public UnSynchronizedReceiver(Data data) {
|
public UnsynchronizedReceiver(Data data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15,10 +19,10 @@ public class UnSynchronizedReceiver implements Runnable {
|
|||||||
data.wait();
|
data.wait();
|
||||||
this.message = data.receive();
|
this.message = data.receive();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
log.error("thread was interrupted", e);
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
} catch (IllegalMonitorStateException e) {
|
} catch (IllegalMonitorStateException e) {
|
||||||
e.printStackTrace();
|
log.error("illegal monitor state exception occurred", e);
|
||||||
illegalMonitorStateExceptionOccurred = true;
|
illegalMonitorStateExceptionOccurred = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,10 +1,14 @@
|
|||||||
package com.baeldung.exceptions.illegalmonitorstate;
|
package com.baeldung.exceptions.illegalmonitorstate;
|
||||||
|
|
||||||
public class UnSynchronizedSender implements Runnable {
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class UnsynchronizedSender implements Runnable {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(UnsynchronizedSender.class);
|
||||||
private final Data data;
|
private final Data data;
|
||||||
private boolean illegalMonitorStateExceptionOccurred;
|
private boolean illegalMonitorStateExceptionOccurred;
|
||||||
|
|
||||||
public UnSynchronizedSender(Data data) {
|
public UnsynchronizedSender(Data data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,10 +21,10 @@ public class UnSynchronizedSender implements Runnable {
|
|||||||
|
|
||||||
data.notifyAll();
|
data.notifyAll();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
log.error("thread was interrupted", e);
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
} catch (IllegalMonitorStateException e) {
|
} catch (IllegalMonitorStateException e) {
|
||||||
e.printStackTrace();
|
log.error("illegal monitor state exception occurred", e);
|
||||||
illegalMonitorStateExceptionOccurred = true;
|
illegalMonitorStateExceptionOccurred = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -30,7 +30,7 @@ public class IllegalMonitorStateExceptionUnitTest {
|
|||||||
void whenSyncSenderAndUnSyncReceiverAreUsed_thenIllegalMonitorExceptionShouldNotBeThrown() throws InterruptedException {
|
void whenSyncSenderAndUnSyncReceiverAreUsed_thenIllegalMonitorExceptionShouldNotBeThrown() throws InterruptedException {
|
||||||
Data data = new Data();
|
Data data = new Data();
|
||||||
|
|
||||||
UnSynchronizedReceiver receiver = new UnSynchronizedReceiver(data);
|
UnsynchronizedReceiver receiver = new UnsynchronizedReceiver(data);
|
||||||
Thread receiverThread = new Thread(receiver, "receiver-thread");
|
Thread receiverThread = new Thread(receiver, "receiver-thread");
|
||||||
receiverThread.start();
|
receiverThread.start();
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ public class IllegalMonitorStateExceptionUnitTest {
|
|||||||
Thread receiverThread = new Thread(receiver, "receiver-thread");
|
Thread receiverThread = new Thread(receiver, "receiver-thread");
|
||||||
receiverThread.start();
|
receiverThread.start();
|
||||||
|
|
||||||
UnSynchronizedSender sender = new UnSynchronizedSender(data);
|
UnsynchronizedSender sender = new UnsynchronizedSender(data);
|
||||||
Thread senderThread = new Thread(sender, "sender-thread");
|
Thread senderThread = new Thread(sender, "sender-thread");
|
||||||
senderThread.start();
|
senderThread.start();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user