title: Java: calling a method from the main thread by signaling in some way from another thread
body: <p>I have an application with 2 threads (the <strong><code>main</code></strong> and another thread <strong><code>t1</code></strong>) which share a volatile variable <strong><code>myVar</code></strong>. Any ideas on how to make the <code>main</code> thread to call a method <strong><code>myMethod</code></strong> by signaling in some way from <code>t1</code> ? 
  I implemented it by using ChangeListener and myMethod is called when myVar changes, BUT the method is called from <strong>t1</strong>, and not from the main thread (note: I need to call this method from the main thread because this is a call to a JavaScript code from Java, so for a security reason only the main thread can do so). Thanks in advance.  </p>