Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [EMF Forms] EMFFormsSWTLayoutDelayed: invalid thread accsess(Multiple Ui Sessions with emf)
[EMF Forms] EMFFormsSWTLayoutDelayed: invalid thread accsess [message #1799701] Wed, 12 December 2018 16:08 Go to next message
Sebastian Fey is currently offline Sebastian FeyFriend
Messages: 4
Registered: December 2018
Junior Member
We have a memory leak in our Rap web application caused by an exception killed thread

this is the exeption:

org.eclipse.swt.SWTException: Invalid thread access
	at org.eclipse.swt.SWT.error(
	at org.eclipse.swt.SWT.error(
	at org.eclipse.swt.SWT.error(
	at org.eclipse.swt.widgets.Widget.error(
	at org.eclipse.swt.widgets.Widget.checkWidget(
	at org.eclipse.swt.widgets.Composite.layout(
	at org.eclipse.emfforms.spi.swt.core.layout.EMFFormsSWTLayoutDelayed$1$
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(
	at org.eclipse.swt.widgets.Display.runPendingMessages(
	at org.eclipse.swt.widgets.Display.safeReadAndDispatch(
	at org.eclipse.swt.widgets.Display.readAndDispatch(
	at org.eclipse.rap.rwt.internal.lifecycle.ProcessAction.execute(
	at org.eclipse.rap.rwt.internal.lifecycle.PhaseExecutor.execute(
	at org.eclipse.rap.rwt.internal.lifecycle.SimpleLifeCycle.execute(
	at org.eclipse.rap.rwt.internal.service.RWTMessageHandler.executeLifeCycle(
	at org.eclipse.rap.rwt.internal.service.RWTMessageHandler.handleMessage(
	at org.eclipse.rap.rwt.internal.remote.MessageChainElement.handleMessage(
	at org.eclipse.rap.rwt.internal.service.LifeCycleServiceHandler.processMessage(
	at org.eclipse.rap.rwt.internal.service.LifeCycleServiceHandler.processUIRequest(
	at org.eclipse.rap.rwt.internal.service.LifeCycleServiceHandler.synchronizedService(
	at org.eclipse.rap.rwt.internal.service.LifeCycleServiceHandler.service(
	at org.eclipse.rap.rwt.engine.RWTServlet.handleValidRequest(
	at org.eclipse.rap.rwt.engine.RWTServlet.handleRequest(
	at org.eclipse.rap.rwt.engine.RWTServlet.doPost(
	at javax.servlet.http.HttpServlet.service(
	at javax.servlet.http.HttpServlet.service(
	at org.eclipse.rap.rwt.osgi.internal.CutOffContextPathWrapper.service(
	at org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl$LegacyServlet.service(
	at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(
	at org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl.doFilter(
	at logging.UserInfoServletFilter.doFilter(
	at org.eclipse.equinox.http.registry.internal.FilterManager$FilterWrapper.doFilter(
	at org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl$LegacyFilterFactory$LegacyFilter.doFilter(
	at org.eclipse.equinox.http.servlet.internal.registration.FilterRegistration.doFilter(
	at org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl.doFilter(
	at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(
	at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(
	at org.eclipse.equinox.http.servlet.internal.servlet.ProxyServlet.service(
	at javax.servlet.http.HttpServlet.service(
	at org.eclipse.equinox.http.jetty.internal.HttpServerManager$InternalHttpServiceServlet.service(
	at org.eclipse.jetty.servlet.ServletHolder.handle(
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(
	at org.eclipse.jetty.servlet.ServletHandler.doScope(
	at org.eclipse.jetty.server.session.SessionHandler.doScope(
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(
	at org.eclipse.jetty.server.Server.handle(
	at org.eclipse.jetty.server.HttpChannel.handle(
	at org.eclipse.jetty.server.HttpConnection.onFillable(
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(
	at org.eclipse.jetty.util.thread.QueuedThreadPool$

Its somethimes, (not always) happens when multiple users open the same Vview or, after opening the VView, clicking concurrently on elements in it.

After the exception, opening any Vview fills the linked hashmap "requestedLayouts" of the class EMFFormsSWTLayoutDelayed, which also contains thread killed by the exception.

this is how we create the view:

  private ViewModelContext createViewModelContext(PackingItem(implements Eobject) packingItem) {
VViewModelLoadingProperties loadingProperties = VViewFactory.eINSTANCE.createViewModelLoadingProperties();

        if (ViewSearchUtils.isViewSearchEnabled()) { //  true or false , makes no memleak difference 
            viewSearchSuggestionProvider = new ViewSearchSuggestionProvider();
            loadingProperties.addInheritableProperty(VIEW_SEARCH_SUGGESTION_PROVIDER, viewSearchSuggestionProvider);
                    new CategorySelectionModel());
        VView view = ViewProviderHelper.getView(packingItem, loadingProperties);
        return ViewModelContextFactory.INSTANCE.createViewModelContext(view, packingItem);

Later, we render it this way:
 try {
            ECPSWTView ecpView = ECPSWTViewRenderer.INSTANCE.render(parent, context);
            GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(ecpView.getSWTControl());
        } catch (ECPRendererException exception) {
            LOG.error("Could not load article view"); //$NON-NLS-1$

I found this issue:
So I put the render method to in an async class we already use:

public abstract class AsyncUiUpdater {

    private Thread bgThread;
    private ServerPushSession pushSession;
    private Exception exception;

    public void start() {

        // init
        pushSession = new ServerPushSession();
        bgThread = new Thread(this::runInBackground);

        // start async session/thread


    private void runInBackground() {

        try (AutoCloseable c = pushSession::stop) {



        } catch (Exception e) {

            this.exception = e;




    private void updateUiSafely(Runnable r) {

        Widget widget = getUpdateableWidget();

        if (widget != null && !widget.isDisposed()) {


     * @return returns exception, if an error occurred
    public Exception getException() {
        return exception;

     * @return UI-Widget, thats need to be updated after work is done
    protected abstract Widget getUpdateableWidget();

     * long work that needs to be done asynchronously, not in the UI-Thread
    protected abstract void doAsyncWork();

     * UI-Updates, after work is done successfully
    protected abstract void onCompletion();

     * UI-Updates, in case of an error in the asynchronous thread
    protected abstract void onError();


public class AsyncRenderer extends AsyncUiUpdater {

    private static final Logger LOG = LoggerFactory.getLogger(AsyncRenderer.class);

    Composite parent;
    ViewModelContext context;

    public AsyncRenderer(Composite parent, ViewModelContext context){
        this.parent = parent;
        this.context = context;

    protected Widget getUpdateableWidget() {
        return parent;

    protected void doAsyncWork() {

    protected void onCompletion() {
        try {
            ECPSWTView ecpView = ECPSWTViewRenderer.INSTANCE.render(parent, context);
            GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(ecpView.getSWTControl());
        } catch (ECPRendererException exception) {
            LOG.error("Could not load article view"); //$NON-NLS-1$

    protected void onError() {
        // TODO Auto-generated method stub


Now, with the async rendering, the view is rendered only once and only in one session, the other sessions won't be able to render it anymore with the async rendering.
Its possible to get the view for some others too if you load the same view/browser tab at the same time.
-> then you are able to get the exeption from above again.
Also, having the auto suggest enabled, searching with it will show the view again.

Refering to the topic I mentioned before, there
has to be some static content shared between the sessions causing the problem.

I'm not that deep in the code of the application, so the static content might be in our code.
But at least, it would be nice if the dead thread in EMF wouldn't cause a leak in this constellation.

Ecore 2.13
Rap rwt 3.4

I just hope someone knows what we might do wrong.

[Updated on: Wed, 12 December 2018 16:11]

Report message to a moderator

Re: [EMF Forms] EMFFormsSWTLayoutDelayed: invalid thread accsess [message #1799791 is a reply to message #1799701] Thu, 13 December 2018 14:26 Go to previous messageGo to next message
Sebastian Fey is currently offline Sebastian FeyFriend
Messages: 4
Registered: December 2018
Junior Member
Figured out that it is a framework bug in the class EMFFormsSWTLayoutDelayed, dev is informed.

[Updated on: Thu, 13 December 2018 14:28]

Report message to a moderator

Re: [EMF Forms] EMFFormsSWTLayoutDelayed: invalid thread accsess [message #1799821 is a reply to message #1799701] Fri, 14 December 2018 09:03 Go to previous message
Eugen Neufeld is currently offline Eugen NeufeldFriend
Messages: 169
Registered: May 2015
Senior Member
Hi Sebastian,

we checked our code.
There is a RAP specific service available: org.eclipse.emf.ecp.view.internal.util.swt.rap.EMFFormsSWTLayoutDirect
It is part of the org.eclipse.emf.ecp.view.util.swt.rap bundle.

The EMFFormsSWTLayoutDelayed is not meant to be used in a RAP environment.

You can also provide your own OSGi Service which implements EMFFormsSWTLayoutOptimizer to override the default behavior (the EMFFormsSWTLayoutDelayed).


Eugen Neufeld

Get professional Eclipse developer support:
Previous Topic:[EMF FORMS] TableControl WithDialog
Next Topic:sub metamodel detection
Goto Forum:

Current Time: Mon May 23 05:50:19 GMT 2022

Powered by FUDForum. Page generated in 0.01693 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top