-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass MDC entries down to Executrix child threads #491
Pass MDC entries down to Executrix child threads #491
Conversation
import static emissary.log.MDCConstants.SHORT_NAME; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class ProcessReaderTest extends UnitTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The public modifier can be removed, but otherwise lgtm
47fb4f7
to
ffe15ca
Compare
…xt capture in log entries
ffe15ca
to
f7c808e
Compare
Two observations...
|
Noted, but not at all within scope of this PR. This comment at the top of /*
* ProcessReader.java
*
* Created on November 19, 2001, 5:28 PM
*/ 🍺
The parent thread 1) creates the child, 2) explicitly passes a point-in-time copy of the context, 3) starts the child, and then 4) uses |
"What is there to synchronize?" The setting of the contextMap attribute of ProcessReader is done by the thread executing the Executrix.execute(...) method (Executrix:835-836), which should be the mobile agent thread. The reading of the contextMap attribute is done by the ProcessReader thread (ProcessReader:39). Therefore, two threads are looking at the same variable. Java threading has many "gotchas" when accessing variables from multiple threads like "atomic access" and "memory consistency errors". This situation falls more into the "memory consistency error" which is defined as "different threads having inconsistent views of what should be the same data". There are a number of ways to solve these types of "gotchas"; however, the simplest in this situation is to wrap all accesses to contextMap with a synchronized block in order to "guarantee that changes to the state of the object are visible to all threads." One place this is described is in the Java Tutorial on Concurrency ( https://docs.oracle.com/javase/tutorial/essential/concurrency/index.html ). The fact that the actual MDC object is thread local, there exists a point-in-time object that is a copy of the MDC objects' state and that the mobile agent thread has "joined" the ProcessReader thread have no bearing on this issue. |
Recapping: you're worried that something might update a ProcessReader's private stdOutThread.setContextMap(MDC.getCopyOfContextMap());
stdErrThread.setContextMap(MDC.getCopyOfContextMap());
stdOutThread.start();
stdErrThread.start(); There aren't two threads looking at the same data: If instead you're worried that the MDC values on the MobileAgent thread could change before the ProcessReader's |
This discussion does not seem to be progressing as we seem to be talking past each other. Given the purpose of this PR, I am ok with the original code changes. |
1fbf899
to
f7c808e
Compare
Popped off the last commit, now back to the previous state. |
Supports additional context capture in log entries