newthreadinterceptionhandlerdecorator.java

来自「基于Junit的 功能和单元测试的的测试工具。只支持Swing.」· Java 代码 · 共 47 行

JAVA
47
字号
package org.uispec4j.interception.handlers;

import org.uispec4j.Window;
import org.uispec4j.utils.ExceptionContainer;

public class NewThreadInterceptionHandlerDecorator extends AbstractInterceptionHandlerDecorator {

  private ExceptionContainer exceptionContainer = new ExceptionContainer();
  private Thread handlerThread;

  public NewThreadInterceptionHandlerDecorator(InterceptionHandler innerHandler) {
    super(innerHandler);
  }

  public void process(final Window window) {
    handlerThread = new Thread() {
      public void run() {
        try {
          NewThreadInterceptionHandlerDecorator.super.process(window);
        }
        catch (Throwable e) {
          exceptionContainer.set(e);
        }
      }
    };
    handlerThread.setName(handlerThread.getName() + " [NewThreadHandler]");
    handlerThread.start();
  }

  public void complete() {
    join();
    exceptionContainer.rethrowIfNeeded();
  }

  public void join() {
    if (handlerThread != null) {
      try {
        handlerThread.join();
        handlerThread = null;
      }
      catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?