HuyPV
Thursday, January 6, 2011
From: http://allabouthobby.blogspot.com/2007/11/j2me-create-new-thread-under.html
Guys, if you happen receive this warning, "To avoid potential deadlock, operations that may block, such as networking, should be performed in a different thread than the commandAction() handler." and your J2ME application doesn't work properly, here is quick work around to do it right :
here is the original line :
public void commandAction(Command c, Displayable s)
{
if (c == cmCall)
{
display.setCurrent(this);
try
{
call_some_function_that_call_network_function();
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
else if (c == cmExit)
{
// the rest command
}
}
and here is the modified line :
public void commandAction(Command c, Displayable s)
{
if (c == cmCall)
{
display.setCurrent(this);
try
{
new Thread(new Runnable()
{
public void run()
{
try{ call_some_function_that_call_network_function();
} catch(IOException e) {}
}
}).start();
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
else if (c == cmExit)
{
// the rest command
}
}
Title:
To avoid potential deadlock, operations that may block
Description:
From : http://allabouthobby.blogspot.com/2007/11/j2me-create-new-thread-under.html Guys, if you happen receive this warning, " To av...
...
Rating:
4