title: Java Thread reading values from other Thread
body: <p>I have a logging thread and a main app thread. </p>
  
  <p>The main app runs every 50ms and has an usual tick length of 11ms to do all its things it needs to do. This 11ms or however long the tick lasted is logged in a variable in the main app in a public field.</p>
  
  <p>In my logging thread i'd like to monitor the variable that keeps track of the average tick length in the main app thread to know when I should throttle the logging because main app flow will always have priority over logging.
  It is a public variable in the main app, unfortunately I have no control over the design of the main app and cannot make it a "thread safe" variable.</p>
  
  <p>However I only want to read it and not write to it.</p>
  
  <p>Can I safely read the variable directly(It doesn't really matter if the data is out of sync for a few microseconds or that i'm running behind on the data) or should I make a thread safe method that reads the variable for me and inject that in the main app via reflection?</p>
  
  <p>What are the possible issues I should keep mind of? And what would be the best approach? </p>
  
  <p>The intent of this question is to get an idea of all issues that could pop up in this scenario and what I should be mindful of. I'm not interested in a patch code solution, but more interested in learning the behaviour of threads and variables between threads and what pitfalls can be..</p>