How to not block ui running plugin in intellij idea

41 Views Asked by At

I'm developing a plugin for intellij. when user clicks on the action, the process will take so long, and there's no way I can reduce time it takes to process and while the process is running, whole intellij is freeze, so I thought maybe starting new thread and do the process inside that thread will stop intellij to freeze but I get the following error:

Current thread: Thread[ApplicationImpl pooled thread 6,4,main] 1624577559
SystemEventQueueThread: Thread[AWT-EventQueue-0,6,main] 40587587 
com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments: EventQueue.isDispatchThread()=false
Current thread: Thread[ApplicationImpl pooled thread 6,4,main] 1624577559
SystemEventQueueThread: Thread[AWT-EventQueue-0,6,main] 40587587

The Action class is:

public class MQLAction extends AnAction {

    @Override
    public void actionPerformed(@NotNull AnActionEvent event) {
        ModuleProjectUtil.getInstance().setEvent(event);
        ModuleProjectUtil.getInstance().setProject(event.getProject());
        Runnable runnable = new RunMqlThread();
        ApplicationManager.getApplication().executeOnPooledThread(runnable);
    }
}

and RunMqlThread is:

public class RunMqlThread implements Runnable{
    @Override
    public void run() {
        if (ActionsUtil.noEditorFound(ModuleProjectUtil.getInstance().getEvent())) {
            return;
        }

        String fileExtension = ActionsUtil.getFileExtension(ModuleProjectUtil.getInstance().getEvent());

        // Check if file is java then insert it if its mql then run it
        boolean isFileJava = fileExtension.equals(JAVA_EXTENSION);
        boolean isFileMQL = fileExtension.equals(MQL_EXTENSION);
        ProjectsMainService mainService = new ProjectsMainServiceImpl();
        if (isFileJava) {
            mainService.importJPO();
        } else if (isFileMQL) {
            mainService.runMQL();
        }
    }
}

What does the error say, and how can I fix it?

0

There are 0 best solutions below