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() )
public void run()
// do whatever needs to be done with the ui.
display.syncexec/asyncexec should be safe when called from any thread, no matter whether it's ui or not.
one might suspect that calling
syncexec from the ui thread results in a deadlock. this is not the case since the
syncexec method checks first whether the calling thread is the ui thread. if so, the
run method of the
runnable is executed immediately.
- How to implement a UI update method that works both with the UI thread and other threads in Eclipse?
- ctrl-click goes to the declaration of the method I clicked. For interfaces with one implementation, how can I just directly go to that implementation?
- How to set JVM arguments in tomcat that work both in eclipse and using the startup.bat
- Eclipse: how to update a JUnit test file with newly added method in the source file?
- How to run a script which has Java command via Eclipse IDE such that I see the output and interact with the program?
- How to set Run Configuration and Debug Configuration in Eclipse to choose the class that has the main method as the start-up class?
- How to vertically align buttons close to each other with no background colour and border line appears only on the top and bottom
- How to update Pandas from Anaconda and is it possible to use eclipse with this last
- How can I automatically update the Javadoc when changing the method signature in Eclipse?
- How do I modify the set method signature that Eclipse auto generates?
- How to download sources and javadoc artifacts with Maven Eclipse plugin from other repository?
- How to launch unit tests under EclEmma without using the VisualVM launcher with that launcher installed
- How can I use classes from other project with maven? (ClassNotFoundException and NoClassDefFoundError is thrown)
- How do I force eclipse to update the apk on my hardware device with each build?
- What is the best open source common lisp implementation that works with Eclipse?
- How can I configure Eclipse, GCC, and OpenOCD to work with the STM32F4Discovery board?
- How to use eclipse with ssh, so that the remote projects can be edited by local eclipse?
- How can I scroll left and right in Eclipse editor with the keyboard without moving the cursor?
- How can I switch to the other pane of editors in Eclipse with a shortcut?
- How to get the enclosing method node with JDT?
- What is the deal with the unicode character 首(U+9996) and how java/mysql deal with it and its friends?
- How to build same source code twice with different dependency version, in both Maven and Eclipse?
- How to Implement the help button with question mark icon on the WizardDialog
- CUDA and Eclipse: How can I tell eclipse that <<< (or >>>) is part of the syntax?
- Problem validating an XSD file: The content type of a derived type and that of its base must both be mixed or both be element-only
- Where to put properties file in eclipse and how to access the path both locally and on server
- How can I take a Drawable that I got from the internet and save it to my Android device in a cache directory?
- how to check the current workspace of Eclipse and the project on that workspace using java program?
- In Eclipse 3.5 (and with the Aptana plugins), how do I get a view that I can use to show my project, including "dot" files?
- How to properly declare in a JSF page that an object is present in the session object with a given type?
More Query from same tag
- Setting C++ build working directory in Eclipse
- Redeploy Dynamic Web Project to Wildfly Server with Eclipse EE
- Selenium Test IEDriver
- The application is installed but not running or visible on virtual device
- Error reading from an IP-Camera
- Stretching an imageview, different on each screen
- Insertion fail with SQL Grammar Exception in Hibernate MySQL 5
- Adding an Android library to a project?
- TestNg Eclipse Plugin - NullPointer when start test
- How to activate auto suggesting in Eclipse ?
- When developing an Android app that uses Wi-Fi Direct, which target SDK should I use?
- Android Studio Error while importing eclipse project
- How to check if log4j.properties is loaded?
- Reassignment of an Exception to the catch parameter
- Why does proceed() give an error
- Account Registeration Issue In Android Device
- Able to select both radio buttons in same group
- Is it possible to have JSON schema autocomplete and documentation with eclipse?
- Android Developers MyFirstApp - "menu cannot be resolved or is not a field"
- Glassfish Server is not starting on eclipse
- Can't find "Set as Django Project" or Django actions in Eclipse with Pydev
- Eclipse debugger breakpoint flakiness w/Glassfish
- Difference between Java working set and Resource working set in Eclipse
- Generate Java Classes from .xsd schema in eclipse
- Not able maven build "strings in switch are not supported in -source 1.5 in eclipse while maven build"
- Clean/Install Multiple maven projects in order without reactor
- Suddenly get ClassNotFoundException in Exception
- eclipse content assist doesn't work on some android type?
- Getting user data in NewProjectCreationPage in Eclipse Plugin
- How to customize vrapper block indentation?