Connection request freeze

48 views
Skip to first unread message

CODENAME1

unread,
Nov 3, 2016, 11:26:56 AM11/3/16
to CodenameOne Discussions
Hi,
When I fire a request ( that implements long poking) which has a default timeout of 1min. And fire another request . Even though the response for the second request is received , the UI doesn't update since it waits for the response of the first request . This gives a freeze effect on the front end.

How can two request work and update ui independently.

I have set updatethreadcount(4).

Steve Hannah

unread,
Nov 3, 2016, 2:10:47 PM11/3/16
to codenameone...@googlegroups.com
For long polling, you probably should use "addToQueueAndWait()".  This uses invokeAndBlock() under the hood which, due to technical reasons, operates as a FILO (first in last out) queue.  invokeAndBlock() is great for shorter tasks, but when they start piling up, you can end up waiting longer than you expect for the first one to return.

Better to do your polling asynchronously.

Steve


--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/f114c572-9816-4aee-9c96-02a9adaac461%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Steve Hannah
Software Developer
Codename One

Steve Hannah

unread,
Nov 3, 2016, 2:16:21 PM11/3/16
to codenameone...@googlegroups.com
On Thu, Nov 3, 2016 at 11:10 AM, Steve Hannah <steve....@codenameone.com> wrote:
For long polling, you probably should use "addToQueueAndWait()". 
I mean *shouldn't* use

On Thu, Nov 3, 2016 at 11:10 AM, Steve Hannah <steve....@codenameone.com> wrote:
For long polling, you probably should use "addToQueueAndWait()".  This uses invokeAndBlock() under the hood which, due to technical reasons, operates as a FILO (first in last out) queue.  invokeAndBlock() is great for shorter tasks, but when they start piling up, you can end up waiting longer than you expect for the first one to return.

Better to do your polling asynchronously.

Steve
On Thu, Nov 3, 2016 at 8:26 AM, CODENAME1 <prity19...@gmail.com> wrote:
Hi,
When I fire a request ( that implements long poking) which has a default timeout of 1min. And fire another request . Even though the response for the second request is received , the UI doesn't update since it waits for the response of the  first request . This gives a freeze effect on the front end.

How can two request work and update ui independently.

I have set updatethreadcount(4).

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsubscr...@googlegroups.com.
--
Steve Hannah
Software Developer
Codename One
Message has been deleted

Cn1

unread,
Nov 7, 2016, 3:29:15 PM11/7/16
to CodenameOne Discussions
I am using addtoqueue() . How can I make connectionrequest behave async


On Thursday, November 3, 2016 at 7:16:21 PM UTC+1, Steve Hannah wrote:
> On Thu, Nov 3, 2016 at 11:10 AM, Steve Hannah <steve....@codenameone.com> wrote:
>
> For long polling, you probably should use "addToQueueAndWait()". 
> I mean *shouldn't* use
>
>
> On Thu, Nov 3, 2016 at 11:10 AM, Steve Hannah <steve....@codenameone.com> wrote:
>
> For long polling, you probably should use "addToQueueAndWait()".  This uses invokeAndBlock() under the hood which, due to technical reasons, operates as a FILO (first in last out) queue.  invokeAndBlock() is great for shorter tasks, but when they start piling up, you can end up waiting longer than you expect for the first one to return.
>
>
> Better to do your polling asynchronously.
>
>
> Steve
>
>
>
>
> On Thu, Nov 3, 2016 at 8:26 AM, CODENAME1 <prity19...@gmail.com> wrote:
> Hi,
>
> When I fire a request ( that implements long poking) which has a default timeout of 1min. And fire another request . Even though the response for the second request is received , the UI doesn't update since it waits for the response of the  first request . This gives a freeze effect on the front end.
>
>
>
> How can two request work and update ui independently.
>
>
>
> I have set updatethreadcount(4).
>
>
>
> --
>
> You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
>
> To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.

Shai Almog

unread,
Nov 8, 2016, 12:46:20 AM11/8/16
to CodenameOne Discussions, niketk...@gmail.com
addToQueue is async. I suggest opening the network monitor and looking at the requests going in/out to see what is stuck and where.

CODENAME1

unread,
Nov 8, 2016, 2:31:25 AM11/8/16
to CodenameOne Discussions
Looking at the network monitor, 

when i fire async( addtoqueue) which has a default timeout of 1min (longpoling- if there is an update , the response is received immediately else a default response is sent after 1 min ). 

In the mean time, if anyother request is fired( async( addtoqueue) with no longpoling, this response is received immediately) but the UI does not update as the connectionrequest is waiting to received the response for the first request( longlong). 

this gives an effect of freeze.

HOw to update the UI, even though another request is waiting for its  response.

Shai Almog

unread,
Nov 9, 2016, 12:51:08 AM11/9/16
to CodenameOne Discussions
If you used addToQueue without wait then the request is happening on the network thread and not on the Codename One thread so the UI isn't waiting for that thread. It is waiting for something else you did in the app.

CODENAME1

unread,
Nov 11, 2016, 4:31:45 AM11/11/16
to CodenameOne Discussions
Is it good to write poling conenction request inside UITImer. (which will try to fetch the response at regular interval)??? or can it lead to UI freeze.

Shai Almog

unread,
Nov 12, 2016, 12:15:46 AM11/12/16
to CodenameOne Discussions
If you keep it at 1 second interval which is pretty low, this won't impact the UI

CODENAME1

unread,
Nov 12, 2016, 4:28:03 PM11/12/16
to CodenameOne Discussions
If the long poling connectionrequest(with addtoqueue)which has a default timeout of 60 sec is fired inside uitimer?!?
Will it freeze or slow UI. If yes, what is the best way to handle.

Shai Almog

unread,
Nov 12, 2016, 10:27:16 PM11/12/16
to CodenameOne Discussions
Sorry had my wires crossed with a different question on media.

You don't need a UITimer in this case, just fire a callSerially when a batch of data arrives

CODENAME1

unread,
Nov 13, 2016, 7:42:55 AM11/13/16
to CodenameOne Discussions
But I need to fetch the data at regular interval. thereby firing the connectionrequest after every 1 min. I do this inside a UiTimer . Is this the correct way to do..wil this freeze the ui. As the response will arrive max after 1 min

Shai Almog

unread,
Nov 14, 2016, 12:20:11 AM11/14/16
to CodenameOne Discussions
You mentioned long polling not polling. Long polling (which is what Steve referred to) is a VERY different technique from polling.

If you use the async code the timer impact will be minimal but you might add requests while others are still pending so you should check that the network manager doesn't have pending requests.
Reply all
Reply to author
Forward
0 new messages