"semaphores" in gwt

391 views
Skip to first unread message

Jaap

unread,
Aug 29, 2009, 8:20:53 PM8/29/09
to Google Web Toolkit
Hi,

When starting my webapp I do two RPC calls. I need the data of both of
them in order to display something. If you work with threads with a
native program you just use semaphores to achieve this. What's the
way to do this in GWT?

Thanks

Jaap

ThomasWrobel

unread,
Aug 29, 2009, 8:36:14 PM8/29/09
to Google Web Toolkit
I think your options are;
a) Just nest one request inside the other.
or
b) Do both requests separately, but within both the OnResponse check a
flag to see if the other one has finished as well. If either flags
that both are done, then trigger the message/code you want to run
based on this.

I think b is better, but I'm sure someone else might have better more
detailed advice.

Christian Goudreau

unread,
Aug 29, 2009, 8:40:07 PM8/29/09
to google-we...@googlegroups.com
Implement a Batch request. You can use the gwt-dispatch project. It's an implementation of the command pattern really well done that allow you to batch request and a lot of thing like rollback, caching, etc.
 
Christian

Message has been deleted

Etienne Neveu

unread,
Aug 30, 2009, 4:20:37 PM8/30/09
to Google Web Toolkit
Woops... Missclicked :/

Let's try again:


------


Thomas and Christian already gave you useful answers.

I want to add the following:

- As of now, Javascript is single threaded , so you don't have
concurrency problems. So you know the onSuccess() method of your RPC
services can not be run concurrently, and you may then use boolean
flags to know whether you already got the other RPC response.
There are some talks of making JavaScript multi-threaded with worker
threads ( https://developer.mozilla.org/En/Using_web_workers ), but
you don't have to worry about that now.

- If you are interested in reducing your app's startup time, you could
avoid the 2 additionnal http requests from the RPC calls by "pre-
loading" the RPC data in your HTML host page, as explained here:
http://www.techhui.com/profiles/blogs/simpler-and-speedier-gwt-with
This technique needs some setup, but it seems like it would be perfect
for your use case.

- If your RPC calls fetch some really simple data like the current
user's nickname/firstname/lastname, you could simply embed this data
inside a javascript variable in your host page, and access it by using
a GWT dictionary.

Regards,

- Etienne

Sumit Chandel

unread,
Sep 2, 2009, 1:54:44 PM9/2/09
to google-we...@googlegroups.com
Hi Jaap,

I would also consider restructuring your code to only require one RPC call, where the data you needed to get from both individual calls can be returned in that one single call. This would be ideal if the payload would still be of a reasonable size as you would avoid extra HTTP roundtrips and sidestep the hit in execution speed when starting up your application using nested calls or waiting on a flag.

Hope that helps,
-Sumit Chandel

JSaar

unread,
Sep 4, 2009, 1:36:45 AM9/4/09
to Google Web Toolkit
2 Options:

make 2 booleans set each in the belonging callback.onSuccess
and check them in both callback.onSuccess
and go on if both are true

On serverside make 1 method out of the 2 you have now
so you have 1 rpc-call

the first way would be the semaphore-way ... standard-business

On Aug 30, 2:20 am, Jaap <jaap.hait...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages