Skip to main content

problems with threads in later versions of LWUIT

6 replies [Last post]
abumami
Offline
Joined: 2007-11-19

Hi,

We have a form that is supposed to be populated in the background with a thread. However, after installing the latest version (versions?) of LWUIT, this mechanism no longer works.

The method that populates the form is simple enough, and is something like this:

public void fillForm()
{
end = start;
actualContent.removeAll();
form.show();

new Thread(new Runnable()
{
public void run()
{
for (int i = start; i < end; i++)
{
ContentItem item = (ContentItem) ContentList.elementAt(i);
addContent(item);
}
}
}).start();
}

Is this a bug in the new version, or has the behavior changed? I looked in the documentation and didn't see any mention of changes in this regard.

Thanks!

Message was edited by: abumami

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mlyons4
Offline
Joined: 2008-07-28

The problem is. When we do a callSerially or callSerialyandWait(Runnable ), we get an IOState exception stating that we cannot call callSerially from the edt and we need this behavior (the Thread to kick in) in response to a Command on the phone?

Francis De Brabandere

That exception indicates you are on the edt, no need to jump to the
edt there, probably that code is somewhere inside an action listener.
If you are doing time-consuming stuff right there you need to start a
new thread, do the non-gui related work and at the end of that thread
jump to the edt using the callSerialy mechanism.

You might want to read some tutorial or article on swing edt (similar
to the lwuit edt) It's not only important to access gui components on
the edt, you should know how to get stuff done off the edt and return
to it when done. (see the blog item from Shai's blog)

you can check if you are on the edt using:
Display.getInstance().isEdt() but most of the time you should be able
to figure that out yourself!

On Tue, Jul 29, 2008 at 10:13 AM, wrote:
> The problem is. When we do a callSerially or callSerialyandWait(Runnable ), we get an IOState exception stating that we cannot call callSerially from the edt and we need this behavior (the Thread to kick in) in response to a Command on the phone?
> [Message sent by forum member 'mlyons4' (mlyons4)]
>
> http://forums.java.net/jive/thread.jspa?messageID=290015
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

abumami
Offline
Joined: 2007-11-19

Hey Francis, my colleague, Moshe (mlyons4) and myself would like to thank you for your help with this. Moshe got it working and after he explained it to me, even I understand what's going on now. It's not as hairy as I thought it would be.

Thanks!

Francis De Brabandere

Accessing/modifying lwuit components should be performed on the event
dispatch thread (edt)!

Try using
Display.getInstance().callSeriallyAndWait(runnable);
or
Display.getInstance().callSerially(runnable);

You need to isolate the time-consuming non-gui stuff to our own thread
and perform the gui stuff on the event dispatch thread using the above
methods.
(see lwuit documentation pdf)

On Mon, Jul 28, 2008 at 11:46 AM, wrote:
> Hi,
>
> We have a form that is supposed to be populated in the background with a thread. However, after installing the latest version (versions?) of LWUIT, this mechanism no longer works.
>
> The method that populates the form is simple enough, and is something like this:
>
> public void addContent()
> {
> end = start;
> actualContent.removeAll();
> form.show();
>
> new Thread(new Runnable()
> {
> public void run()
> {
> for (int i = start; i < end; i++)
> {
> ContentItem item = (ContentItem) ContentList.elementAt(i);
> addContent(item);
> }
> }
> }).start();
> }
>
> Is this a bug in the new version, or has the behavior changed? I looked in the documentation and didn't see any mention of changes in this regard.
>
> Thanks!
> [Message sent by forum member 'abumami' (abumami)]
>
> http://forums.java.net/jive/thread.jspa?messageID=289750
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

abumami
Offline
Joined: 2007-11-19

> Accessing/modifying lwuit components should be
> performed on the event
> dispatch thread (edt)!
>
> Try using
> Display.getInstance().callSeriallyAndWait(runnable);
> or
> Display.getInstance().callSerially(runnable);

Thanks. I've already looked into this stuff and we're now investigating how we can use it for our background stuff.

The thing is, the thread from my original post works in an older (not ancient) version of LWUIT. It's only when I upgraded to one of the new versions (from June?) that it stopped working.

Am I to assume that a "standard" thread won't work in LWUIT and that the only mechanism that will be supported is the EDT dispatch?

Francis De Brabandere

Threading bugs are nasty beasts, non-edt code might run at some point
but is likely to break because of race conditions and other threading
issues.
Doing everything on the edt is the nr 1 rule for using lwuit (and swing)

see this blog post for info on implementing background loading (the
BackgroundTask part)
http://lwuit.blogspot.com/2008/05/progress-indicator-threads-in-lwuit.html

On Tue, Jul 29, 2008 at 8:05 AM, wrote:
>> Accessing/modifying lwuit components should be
>> performed on the event
>> dispatch thread (edt)!
>>
>> Try using
>> Display.getInstance().callSeriallyAndWait(runnable);
>> or
>> Display.getInstance().callSerially(runnable);
>
> Thanks. I've already looked into this stuff and we're now investigating how we can use it for our background stuff.
>
> The thing is, the thread from my original post works in an older (not ancient) version of LWUIT. It's only when I upgraded to one of the new versions (from June?) that it stopped working.
>
> Am I to assume that a "standard" thread won't work in LWUIT and that the only mechanism that will be supported is the EDT dispatch?
> [Message sent by forum member 'abumami' (abumami)]
>
> http://forums.java.net/jive/thread.jspa?messageID=290000
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net