您的位置:首页 > 编程语言 > Java开发

【eclipse rcp】判断当前线程是否是界面线程

2013-10-28 09:55 176 查看
    public static boolean isUIThread()

    {

        Object uiThread = null;

        try

        {

            Class displayClass = Class.forName("org.eclipse.swt.widgets.Display");

            Method getDefaultMethod = displayClass.getDeclaredMethod("getDefault", new Class[] {});

            Object display = getDefaultMethod.invoke(null, new Object[] {});

            Method getThreadMethod = displayClass.getDeclaredMethod("getThread", new Class[] {});

            uiThread = getThreadMethod.invoke(display, new Object[] {});

        }

        catch (Exception e)

        {

            // log.warn("Could not determine UI thread using reflection", e);

        }

        return (Thread.currentThread() == uiThread);

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: