Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT widgets take no command under asynchronous http request callback
SWT widgets take no command under asynchronous http request callback [message #1854871] Thu, 15 September 2022 20:20 Go to next message
Yue Yang is currently offline Yue YangFriend
Messages: 13
Registered: December 2019
Junior Member
SWT widget code inside callback will never work.
CloseableHttpAsyncClient http = HttpAsyncClients.createDefault();
http.start();
http.execute(request, new FutureCallback<HttpResponse>() {
    @Override
    public void completed(HttpResponse response) {
        System.out.println("Hello"); // this works
        // StyledText widget st
        st.setText("Hello"); // never works
        System.out.println("Hello"); // never prints
    }
    
    @Override
    public void failed(Exception e) {
    
    }
    
    @Override
    public void cancelled() {
    
    }
});

Though the SWT code doesn't work, it throws no error.
Below code works:
HttpResponse response = http.execute(request, null).get();
st.setText("Hello");

Using
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpasyncclient</artifactId>
    <version>4.1.5</version>
</dependency>

How is asynchronous and concurrent request achieved in Eclipse?

[Updated on: Fri, 16 September 2022 00:03]

Report message to a moderator

Re: SWT widgets take no command under asynchronous http request callback [message #1854875 is a reply to message #1854871] Fri, 16 September 2022 00:27 Go to previous messageGo to next message
Yue Yang is currently offline Yue YangFriend
Messages: 13
Registered: December 2019
Junior Member
Alright, not until getting in touch with this issue did I realized that SWT has its own solution for asynchronous and concurrent tasks (Display.getCurrent().asyncExec(new Runnable(){})). Solved now.

Reference: https://blog.csdn.net/iteye_5335/article/details/81575677
Re: SWT widgets take no command under asynchronous http request callback [message #1854924 is a reply to message #1854875] Mon, 19 September 2022 00:00 Go to previous message
Andy Maleh is currently offline Andy MalehFriend
Messages: 75
Registered: March 2020
Location: Montreal, Quebec, Canada
Member
When you are operating within a different thread, you must execute all SWT code using Display syncExec or asyncExec (or other variations like syncCall)

EclipseCon / EclipseWorld / Agile Conference Speaker
Open-Source Software Author of Glimmer DSL for SWT
Previous Topic:HelloWorld SWT application
Next Topic:Failed to unregister class Chrome_WidgetWin_0. Error = 0
Goto Forum:
  


Current Time: Mon May 06 16:26:54 GMT 2024

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

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

Back to the top