title: How to call JAWT_FreeDrawingSurface from another thread?
body: <p>I have an application using Swing and LWJGL running nice and stable using a dedicated rendering thread. I have made sure all OpenGL and JAWT calls are made on my rendering thread and not on EDT (this includes <code>JAWT_GetDrawingSurface</code>, <code>JAWT_DrawingSurface_Lock</code>, <code>JAWT_DrawingSurface_Unlock</code>).</p>
  
  <p>My threads are Java threads, <code>JAWT_xxxx</code> functions are called from the <code>org.lwjgl.opengl.awt</code> toolkit, I have currently no native code of my own.</p>
  
  <p>There is one call left which is done from the AWT thread when the UI components arfe disposed: <code>JAWT_FreeDrawingSurface</code> called from <code>org.lwjgl.opengl.awt.PlatformWin32GLCanvas#dispose</code>. One solution would be to create a customized version of all <code>org.lwjgl.opengl.awt</code> classes and prevent this call being made (and call it from my thread instead). While this is possible, before I do so, I would like to check if there is perhaps another solution?</p>
  
  <p>The documentation for <a href="https://docs.oracle.com/javase/9/docs/specs/AWT_Native_Interface.html" rel="nofollow noreferrer">The Java AWT Native Interface</a> quotes the source comments - <code>struct jawt_DrawingSurface</code>):</p>
  
  <p>First:</p>
  
  <pre><code>/*
   * JAWT_DrawingSurface
   * Structure for containing the underlying drawing information of a component.
   * All operations on a JAWT_DrawingSurface MUST be performed from the same
   * thread as the call to GetDrawingSurface.
   */
  </code></pre>
  
  <p>and later:</p>
  
  <pre><code>    /* Cached reference to the Java environment of the calling thread.
       * If Lock(), Unlock(), GetDrawingSurfaceInfo() or
       * FreeDrawingSurfaceInfo() are called from a different thread,
       * this data member should be set before calling those functions.
       */
       JNIEnv* env;
  </code></pre>
  
  <p>I read the second paragraph as "it is possible to call the functions from a different thread, but a special care needs to be taken". What is not clear to me is: how do I set this data member before calling those functions? Is this something that can be done from Java, or do I need a native code for that?</p>