title: Java SWT Invalid thread access
body: <p>I have java project, which lanches two SWT dialogs, for some input. Sometime I got below exception while launch dialog. I googled it but found only display init issue. But i got shell init issue. Can some one help me on this. </p>
  
  <p><strong>Sample Code</strong></p>
  
  <pre><code> public static Display getDisplay ()
              {
                  Display display = Display.getCurrent ();
                  // may be null if outside the UI thread
                  if (display == null)
                      display = Display.getDefault ();
                  return display;
              }
             Display display = getDisplay(); 
             Shell shell = new Shell(display);
  </code></pre>
  
  <p><strong>Excepton</strong></p>
  
  <pre><code>org.eclipse.swt.SWTException: Invalid thread access
                  at org.eclipse.swt.SWT.error(SWT.java:4441)
                  at org.eclipse.swt.SWT.error(SWT.java:4356)
                  at org.eclipse.swt.SWT.error(SWT.java:4327)
                  at org.eclipse.swt.widgets.Widget.error(Widget.java:476)
                  at org.eclipse.swt.widgets.Shell.&lt;init&gt;(Shell.java:283)
                  at org.eclipse.swt.widgets.Shell.&lt;init&gt;(Shell.java:274)
                  at org.eclipse.swt.widgets.Shell.&lt;init&gt;(Shell.java:224)
                  at gui.lms.analysisRequestGUI.GenericDialog.showDialog(Unknown Source)
                  at gui.teamcenter.gui.actions.PublishAction$1.execute(Unknown Source)
                  at base_gui.basegui.util.WorkerThread.run(Unknown Source)
  </code></pre>