1 /*******************************************************************************
2 * Copyright (c) 2007, 2020 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 * Semantum Oy - gitlab #522 - removed reflection hack
12 *******************************************************************************/
15 * @author Toni Kalajainen
17 package org.simantics.utils.threads;
19 import java.awt.EventQueue;
20 import java.lang.reflect.InvocationTargetException;
21 import java.util.List;
22 import java.util.concurrent.AbstractExecutorService;
23 import java.util.concurrent.Executor;
24 import java.util.concurrent.TimeUnit;
26 import javax.swing.SwingUtilities;
29 public class AWTThread extends AbstractExecutorService implements IThreadWorkQueue, Executor {
31 public static AWTThread INSTANCE = new AWTThread();
33 public static IThreadWorkQueue getThreadAccess()
39 public Thread asyncExec(Runnable runnable) {
40 EventQueue.invokeLater(runnable);
45 public boolean syncExec(Runnable runnable) {
46 if (EventQueue.isDispatchThread())
53 SwingUtilities.invokeAndWait(runnable);
55 } catch (InterruptedException e) {
56 throw new RuntimeException(e);
57 } catch (InvocationTargetException e) {
58 throw new RuntimeException(e.getCause());
63 public boolean currentThreadAccess() {
64 return EventQueue.isDispatchThread();
68 public Thread getThread() {
72 public String toString() {
77 public void execute(Runnable command) {
78 EventQueue.invokeLater(command);
82 public void shutdown() {
86 public List<Runnable> shutdownNow() {
91 public boolean isShutdown() {
96 public boolean isTerminated() {
101 public boolean awaitTermination(long timeout, TimeUnit unit)
102 throws InterruptedException {