My sample code posted below shows two classes. One implements KeyListener and the other implements Runnable and is running in an infinite loop sleeping every 20 ms. When a k
When it comes to AWT or Swing the number one rule is do not ever synchonize or otherwise interfere with the dispatch thread. If you're not familiar with this then take a look at Dispatch Thread Issues
In your case I would separate the non GUI thread functionality into a separate class altogether - and use one of the really useful classes in java.util.concurrent to communicate between the two if necessary.
If you get a lock or delay due to threading issues and you're actually in the Dispatch Thread whole GUI will freeze