Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7602069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:19:08+00:00 2026-05-30T23:19:08+00:00

I am implementing a method that updates UI and can be executed either from

  • 0

I am implementing a method that updates UI and can be executed either from the UI thread or from other threads. According to Javadocs, in the latter case Display.syncExec() or Display.asyncExec() methods should be used. Do I have to check whether my method is executed in the UI thread or syncExec/asyncExec is suitable for both cases?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:19:09+00:00Added an answer on May 30, 2026 at 11:19 pm

    Executing Display.syncExec/asyncExec is safe from any thread (including the UI thread), but it isn’t always the best route. For instance, asyncExec will always add your runnable into the queue to execute later even if you are already on the UI thread. Depending on your usecase, that may or may not be desirable. Often, if you known you are already on the UI thread, it is better to just go ahead and execute the work item.

    I like to use the following snippet in any method that needs to update UI and may be called from a non-UI thread. If called from UI thread, it executes the work immediately. If called from other thread, it uses asyncExec to schedule work in the next batch without blocking the calling thread.

    public void task()
    {
        if( this.display.getThread() != Thread.currentThread() )
        {
            this.display.asyncExec
            (
                new Runnable()
                {
                    public void run()
                    {
                        task();
                    }
                }
            );
    
            return;
        }
    
        // Do whatever needs to be done with the UI.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Where can I get info about implementing my own methods that have the ellipsis
From what I can see, the ForEach method is available only for the List
UPDATE: I tried implementing the method specified by Peter and am getting incorrect shadowing.
I'm updating my code generator and have a choice between implementing a method stub
I'm implementing type-independent method for filling DataRow with values. Intended functionality is quite straight
In Twisted when implementing the dataReceived method, there doesn't seem to be any examples
What is the preferred method for implementing such geometric distortions as pinch/fisheye/etc. using the
What is the current method of implementing the joined-subclass structure with FluentNHibernate? By current,
Is it necessary to set large objects to null when implementing a Dispose() method?
I'm not sure about clarity of the STAR word. I'm implementing a search method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.