How to not block ui thread with this code

Hello, I have the following code snippet in my intellij plugin.

        //invoke later because it reads from other threads(debugging executer)         app.invokeLater(new Runnable() {             @Override             public void run() {                 if (isDebugMode) {                     final String initializeMsg = String.format(DEBUG_TCP_MESSAGE, configuration.getRunnerParameters().getPort());                     //this should wait until the deployment states that it's listening to the port                     while (!outputForwarder.toString().contains(initializeMsg)) {                     }                   //do some other code                 }             }         }, ModalityState.NON_MODAL);

so the while loop seems to block the UI thread in my intellij plugin, how can I rewrite this so it doesn't block the UI thread and I wait till the while loop finishes to execute the other code in this method?

Comment actions Permalink

If you need your code to be executed on a background thread, you should use Application.executeOnPooledThread() instead of Application.invokeLater() to execute it.

Comment actions Permalink

I change it to that and now I get the following error:

    Access is allowed from event dispatch thread only.
           Details: EventQueue.isDispatchThread()=false
           Current thread: Thread[ApplicationImpl pooled thread 17,4,main] 1043770989
           SystemEventQueueThread: Thread[AWT-EventQueue-1 14.1.3#IC-141.1010.3, eap:false,6,main] 1894313674
           "AWT-EventQueue-1 14.1.3#IC-141.1010.3, eap:false" prio=0 tid=0x0 nid=0x0 runnable
           java.lang.Thread.State: RUNNABLE
           at com.intellij.diagnostic.IdeErrorsDialog.getSubmitter(
           at com.intellij.diagnostic.DefaultIdeaErrorLogger.canHandle(
           at com.intellij.diagnostic.DialogAppender.appendToLoggers(
           at com.intellij.diagnostic.DialogAppender$
           at java.awt.event.InvocationEvent.dispatch(
           at java.awt.EventQueue.dispatchEventImpl(

Comment actions Permalink

This does not look like a complete stacktrace. What code exactly are you trying to execute in a background thread?


Please sign in to leave a comment.