GWT has anything like Thread.sleep();

8,026 views
Skip to first unread message

Mike Wannamaker

unread,
Mar 1, 2007, 12:06:56 PM3/1/07
to Google-We...@googlegroups.com
Does GWT have anything like Thread.sleep(1000);?

I need to do something like
while(thisIsNotDoneYet())
{
Thread.sleep(1000);
}

Mike Wannamaker

Kirin

unread,
Mar 1, 2007, 12:08:58 PM3/1/07
to Google Web Toolkit
you can have a look at GWT timer
and make a run() method which check your boolean

uwfrog

unread,
Mar 1, 2007, 12:09:51 PM3/1/07
to Google Web Toolkit
I don't think so. Javascript is single-threaded, i believe.

Jon Wells

unread,
Mar 1, 2007, 12:27:32 PM3/1/07
to Google Web Toolkit
Correct, the execution environment is single-threaded. In general,
your translatable code should never block (hence the AsyncCallback
stuff).

Jon

Dan Morrill

unread,
Mar 1, 2007, 12:40:12 PM3/1/07
to Google-We...@googlegroups.com

Hello!

Actually, everyone is correct. (I love threads where I can say that. :)

It is indeed true that JavaScript is single-threaded, which is why all of GWT's libraries are based around asynchronous callbacks, and so on.  It's also true that there is no direct way to perform a Thread.sleep(), since that would be an inherently synchronous call.

However, as Kirin pointed out, you can achieve a similar effect using a Timer.  The general strategy is that you take all the code you want to run after the sleep, and schedule it to run in 1000 milliseconds using a Timer object.  This may require some restructuring of your code, to do correctly.

If you need more help, feel free to post the code you're trying to use, Mike!

- Dan Morrill

Mike Wannamaker

unread,
Mar 1, 2007, 1:30:17 PM3/1/07
to Google-We...@googlegroups.com

I don't think the timer will work, basically I was just wondering if someone clever out there had something like that, didn't think so..  Basically the code is as I said, however the call to

 

While(myObject.hasNotReturnedFromItsRPCCallYet())

{

          pauseForABit();

}

 

Just didn't want to have to register another callback with myObject to do what I wanted to do after the pause(); no worries just as easy to do the callback.

 

Mike Wannamaker

Senior Software Developer 

 


Chad Bourque

unread,
Mar 1, 2007, 1:50:13 PM3/1/07
to Google-We...@googlegroups.com
Mike,
 
If you just want to wait until your async call returns, why not do something like this:
 
// some code that runs before your call
// your call to RPC
RPC.getInstance().getObject(new AsyncCallback() {
  public void onFailure(Throwable caught) {}
  public void onSuccess(Object result) {
    setup();
  });
 
private void setup() {
  // rest of code that needs to wait for object
}
 
Now, if you need to wait on multiple calls, it can be as simple as adding this to the above code:
 
private int counter = 0;
 
// in the onSuccess of each RPC callback handler before the call to setup
counter++;
 
// at the top of the setup() method
if (counter < 2) {
  return;
}
 
The 2 will be replaced with the number of async calls you are waiting on.
 
HTH,
Chad
 
--
There are two types of people in the world:
  * Those who need closure

mike...@gmail.com

unread,
Mar 1, 2007, 5:30:10 PM3/1/07
to Google Web Toolkit
Try running this native javvascript method:

<script language="javascript">
<!--
function wait(millis)
{
var start = new Date();
var wait = true;
while (wait)
{
var end = new Date();
wait = ((start.getTime() + millis) >= end.getTime());
}
alert("done...");
}
-->
</script>

Andrés Testi

unread,
Mar 1, 2007, 6:45:36 PM3/1/07
to Google Web Toolkit
I hope see blocking methods in GWT > 1.4
I we have the compiler, we can do it.

Imagine a method scoped @Blocking annotation. When the compiler find a
call to a @Blocking method, it can separate the invoker method in two
native functions. Code before the call is translated to an invoking
function, and code after call is translated to a callback.
A blocking system is possible or I'm wrong?

Andrés Testi

unread,
Mar 1, 2007, 6:52:22 PM3/1/07
to Google Web Toolkit
With a blocking feature, RPC callbacks are simplified

Reinier Zwitserloot

unread,
Mar 1, 2007, 8:00:19 PM3/1/07
to Google Web Toolkit
Mike Viens:

You should be shot.

NB: Because I will get flamed for this, let me be a bit more clear:
Tossing your javascript into an endless loop the way you're doing will
completely freeze out the browser and make your CPU hit the high end
of death valley temperatures in the dead of summer. This will in turn
cause notebooks to emulate a particularly eager vacuum cleaner whilst
simultaneously dropping the remaining juice from that poor poor
battery as fast as a gerbil tossed off the empire state.

In short, people the world over will be cussing at you for a long time
to come, and that might be construed as sufficient pain that you ought
to take a paintball right in the solar plexus.

HTH!

sha-india

unread,
Mar 2, 2007, 4:23:36 AM3/2/07
to Google Web Toolkit
heehe :)

agreed with reiner ...
since my dear friend does make gwt devv a lil more interesting ...

only one correction here ->

> completely freeze out the browser and make your CPU hit the high end
> of death valley temperatures in the dead of summer.

u mean in the dead of *winter* ! :)

mike...@gmail.com

unread,
Mar 2, 2007, 6:33:50 PM3/2/07
to Google Web Toolkit
Reiner, by posting a code snippet to a forum does not result in
everyone in the known IT world using it. The author asked for how to
do something, so I provided it. As the author is HIS code, I am going
to assume he knows best what should or should not be done within it.
You cannot possibly know the reason(s) for his needing a wait()
method, but the fact he does means that something else is not meeting
his needs.

To know WHEN to use code like this is what will his project work as
expected or not.

And, by the way, I hope you certainly realize that making a threat via
the internet is a serious offense. Your opening line of "You should
be shot" I am sure was meant as nothing more than a simple attempt at
humor. If not, please enlighten me further...

Mike V.

On Mar 1, 5:00 pm, "Reinier Zwitserloot" <reini...@gmail.com> wrote:
> MikeViens:

Reinier Zwitserloot

unread,
Mar 2, 2007, 7:44:56 PM3/2/07
to Google Web Toolkit
I've replied to Mike by way of email and while I appreciate the
laughs, this thing is rapidly veering off topic. I would appreciate
that this thread see no more commentary. You have my gratitude.

NB: As I have an image to uphold, I certainly don't want to create the
impression that Mike's thinly veiled legal threat in any way or form
scared me. Rest assured that my reply has been sautéed with a number
of juicy remarks that would make a litigious bastard wet himself with
glee.

HTH!

mike...@gmail.com

unread,
Mar 5, 2007, 12:18:33 PM3/5/07
to Google Web Toolkit
And, for all to see, here is the "magnificent" reply from Reinier...

> Reiner, by posting a code snippet to a forum does not result in
> everyone in the known IT world using it. The author asked for how to
> do something, so I provided it.
>

>if someone asks you for a rope so that he may hang himself, you hand
>it over too? Don't be an idiot. The code snippet you wrote is wrong to
>bloody wrong in all possible circumstances. It served to confuse and
>nothing more. Hopefully. The alternative is that that monstrous bit of
>duck vomit actually gets used, in which case you are personally
>responsible for a lot of grief.


>
>
>> And, by the way, I hope you certainly realize that making a threat via
>> the internet is a serious offense. Your opening line of "You should
>> be shot" I am sure was meant as nothing more than a simple attempt at
>> humor. If not, please enlighten me further...
>>
>

>Yes, of course, because making thinly veiled legal threats means you
>clearly have the moral high ground.
>
>Fortunately for me, I don't live in a country with inane litigious
>idiots.
>
>HTH!

Truly, classy and professional, Reinier. Thank you for your bizarre
opinion. As for "thinly veiled", make another and we shall see...
Regarding your "reputation to uphold", indeed you do have one. After
a very quick search, I found many other people that you have conversed
with, and I must say that you are consistent in your manner. I
believe you do have some valid points, but your approach is rude,
crass, and juvenile. But, that goes along with being only 25, doesn't
it? (No insult meant toward all 25 year olds...) I was there once,
and I thought I knew a lot, too. I think when you grow out of your
rebelious, angry stage, you may actually benefit the IT world. Until
then though, you are not helping anyone and are making quite a fool of
yourself, which you will probably regret as you mature.

BTW, you really make it very easy to find information about yourself,
don't you?

http://www.zwitserloot.com/
http://www.blogger.com/profile/13753148

Reinier Zwitserloot
Papsouwselaan 54
Delft
,2624EB
NL
Tel. +31.652391707

Dan Morrill

unread,
Mar 5, 2007, 5:47:28 PM3/5/07
to Google-We...@googlegroups.com

At this point, I find it necessary to be absolutely crystal clear:

Rudeness in any form, including disrespect, is not welcome and will not be tolerated.

Please understand that it is not my intention to dictate the kinds of conversations people can have, or to rule the forum with an iron fist.  However, this is a forum for discussing the Google Web Toolkit, and nothing else.  We are all developers here, some professionally, some as students, and even some as hobbyists.  I strongly believe that we are all worthy of each others' patience and respect.  There are users on this list who need help and want to discuss interesting technical problems.  There is enough for us to spend our time on, without sarcasm, flame wars, and recriminations.

Mike, I find your response to be as inappropriate as Reinier's.  I understand that Reinier's abrasive comments have annoyed a number of people, and I am absolutely sympathetic to your desire to respond.  However, if you (or anyone else) do choose to address another member, please take the high road and limit it to his or her language, and refrain from personal attacks.


I ask that everyone please nip this in the bud.  It is my responsibility to make sure that this list is an effective support avenue for GWT users.  If anyone consistently gets in the way of that goal, I will have to use the moderator's ability to ban users.  I am an engineer, and I don't want to be the mailing list police.  No user has yet been banned from this group (except for spam), and I don't want to start.

- Dan

P.S. - I am also going to close out this thread for future responses.  I apologize for taking this action, and if anyone wants to discuss this further, please feel free to contact me directly.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages