How to use java.lang.Thread in GWT

6,113 views
Skip to first unread message

Adil Ben

unread,
May 28, 2009, 12:37:49 PM5/28/09
to Google Web Toolkit
Hello,

I need to call the method Thread.sleep() in my GWT code. But GWT does
not integrate this class.
How to solve this?

i get the following error
"No source code is available for type java.lang.Thread; did you
forget to inherit a required module?"

Regards.

Jason Essington

unread,
May 28, 2009, 12:52:28 PM5/28/09
to Google-We...@googlegroups.com
Thread is not part of java that is emulated in GWT. Javascript is
single threaded so thread.sleep() has no meaning, you might as well do
while(true); (I don't actually suggest doing that)

What is it that you are trying to accomplish with Thread.sleep()?

-jason

Adil BENHAMID

unread,
May 28, 2009, 1:03:35 PM5/28/09
to Google-We...@googlegroups.com
I would like to to make a temporization between two calls.

2009/5/28 Jason Essington <jason.e...@gmail.com>



--
¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø¤º°`°º¤ø,¸¸,ø¤º°`°
Adil BENHAMID
º¤ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø

Adil BENHAMID

unread,
May 28, 2009, 1:05:46 PM5/28/09
to Google-We...@googlegroups.com
as an example I want to display a button then wait two seconds before displaying the next one.

2009/5/28 Adil BENHAMID <enst.de....@gmail.com>

Paul Grenyer

unread,
May 28, 2009, 1:07:20 PM5/28/09
to Google-We...@googlegroups.com
Sounds like you need a timer. Can you not make both calls on the server side?

Sent from my BlackBerry® wireless device


From: Adil BENHAMID
Date: Thu, 28 May 2009 17:03:35 +0000
To: <Google-We...@googlegroups.com>
Subject: Re: How to use java.lang.Thread in GWT

Paul Grenyer

unread,
May 28, 2009, 1:07:49 PM5/28/09
to Google-We...@googlegroups.com
Sounds like a timer to me.

Sent from my BlackBerry® wireless device


From: Adil BENHAMID
Date: Thu, 28 May 2009 17:05:46 +0000


To: <Google-We...@googlegroups.com>
Subject: Re: How to use java.lang.Thread in GWT

davidroe

unread,
May 28, 2009, 1:08:42 PM5/28/09
to Google Web Toolkit
Timer t = new Timer() {
public void run() {
// do something after a delay
}
};

// delay running for 2 seconds
t.schedule(2000);

HTH,
/dave

On May 28, 10:05 am, Adil BENHAMID <enst.de.breta...@gmail.com> wrote:
> as an example I want to display a button then wait two seconds before
> displaying the next one.
>
> 2009/5/28 Adil BENHAMID <enst.de.breta...@gmail.com>
>
>
>
> > I would like to to make a temporization between two calls.
>
> > 2009/5/28 Jason Essington <jason.essing...@gmail.com>

Donald.W.Long

unread,
May 29, 2009, 8:20:08 AM5/29/09
to Google Web Toolkit
If you need to make something occur sequential that is happening in
events, I did the following.

This is the issue I had.

In loading my screen up with I needed to build part of the screen
(buttons and the like) from data received from the server. Thus,
until this data was received some init work could not be completed.
The part that build up the buttons from the server was a separate
subsystem I was using. Thus I created a class that would us this
subsystem and attach to its event handling (this was part of the
subsystem) and when the event was fired it would use the data from the
server to build its part of the screen and then call another method
that was linked with it to complete the init functions.


The below code is the main part of the init for the application. The
last line is a class that creates a master menu from the server. It
requires a class to be passed that I used to complete the init. This
class is used after it has completed its code, thus allowing you to
have sequential initialization.


// Setup the header
//@ TODO Get the root URL
Header.setUrl(result + "/Pages/Header.html");
Header.setStyleName("Header");
Header.setSize(HeaderWidth + "px", HeaderHeight + "px");

// Setup the page
Page.setStyleName("Page");
Page.setSize(PageWidth + "px", PageHeight + "px");

// Setup the notice panel
//@ TODO: Notice.setStyleName("NoticePanel");
Notice.setSize(NoticeWidth + "px", NoticeHeight + "px");
Label x1 = new Label("We have a notice");
Label x2 = new Label("We have another notice");
Notice.add(x1);
Notice.add(x2);

// Setup the quick menu
SetupQuickMenu();

// Setup the menu
myMenu = new MasterMenu(Page, ButtonWidth, myOnComplete);


The last line created a class that had an event that would talk to the
server getting data about how to build up several buttons, after it
completed its event the event would call a method in the class
myOnComplete, thus forcing a sequential init for the application.

See below

private class onxComplete implements MasterMenuComplete {

@Override
public void onComplete() {
Menu.setSize(MenuWidth + "px", MenuHeight + "px");
Menu.add(myMenu.getStackPanel(), StackPanelLeft, StackPanelTop);

// Setup the master panel
MasterPanel.setSize(MasterPanelWidth + "px", MasterPanelHeight +
"px");
//# TODO: MasterPanel.setStyleName("MasterPanel");
MasterPanel.add(Header, HeaderLeft, HeaderTop);
MasterPanel.add(Menu, MenuLeft, MenuTop);
MasterPanel.add(Page, PageLeft, PageTop);
MasterPanel.add(QuickMenu, QuickMenuLeft, QuickMenuTop);
MasterPanel.add(Notice, NoticeLeft, NoticeTop);

// Display root panel.
RootPanel.get("maindisplay").add(MasterPanel);

// Fire off the default button.
myMenu.clickDefault(); }
};



The Async call back class is below

AsyncCallback<ButtonRec[]> callback = new AsyncCallback<ButtonRec[]>()
{
String groupName = "";
ButtonGroup group;

@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub

}

@Override
public void onSuccess(ButtonRec[] result) {
if (result.length > 0) {
for (int i=0; i < result.length; i++) {
if (groupName.compareTo(result[i].getGroupName()) != 0) {
group = new ButtonGroup(result[i].getGroupName(), -1, "", 0);
group.setMaintainState(true);
groupName = result[i].getGroupName();
myMenu.Add(group);
}
if (result[i].isDefaultButton()) {
group.setDefaultButton(new MyMenuButton(
group, result[i].getButtonName(),
result[i].getURL(), ButtonWidth,
MenuButtonHandler));
} else {
new MyMenuButton(
group, result[i].getButtonName(),
result[i].getURL(), ButtonWidth,
MenuButtonHandler);
}
}
myMenu.LoadMenu();
CompleteCall.onComplete();
}
}

};


The last call CompleteCall.onComplete() is the class that was
registered with the MasterMenu class. After it creates its buttons it
then calls this method to complete init of the application.

I did this just to figure out how to have sequential init when dealing
with events.

It works, a bit complicated but given the limitation of the browser
environment you really do not have a lot of choices.
> > º¤ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø- Hide quoted text -
>
> - Show quoted text -

Jason Essington

unread,
May 29, 2009, 10:38:44 AM5/29/09
to Google-We...@googlegroups.com
Use the GWT timer for that

-jason

Jason Essington

unread,
May 29, 2009, 10:48:35 AM5/29/09
to Google-We...@googlegroups.com
In reality, if the second button depends upon the response of some XHR triggered by a click of the first button, even a timer is a poor choice.

You would want to use callbacks.

have a look at the short explanation here:

-jason

On May 28, 2009, at 11:05 AM, Adil BENHAMID wrote:

Reply all
Reply to author
Forward
0 new messages