Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

deadlock and thread

0 views
Skip to first unread message

focode

unread,
Dec 1, 2009, 9:56:25 AM12/1/09
to
i am a j2me programmer and facing some problem , problem statement is
as follows ..

i have "main" java program usually called as midlet , and several
other java programs which is called by the main program to perform
several task such as sending and receiving sms etc.

my main program send sms to a particular number eg "53030" and waits
for sms to be received in the j2me application , sms comming from
server takes some time , in the mean time , my application is hanged ,
and as soon as the sms is received , hanging problem or deadlock
situation come to an end , if i use threads i think this problem will
be eliminated , i need suggestion as to how to implement thread and
eliminate my problem .

sms recieving program contains a mandatory fuction, that does the job
of listening the sms .

any solution will be of general type as it is implemented in j2se .

pseudo implementation of the programs are as follows :

// structure of main program
public class main_program
{

public static void main (String str[])
{

sms s = new sms() // when this fuction is called my
application goes into deadlock state
String sms_recevied = s.listen(); // calling the
sms class to receive sms
System.out.println(sms_recevied); // printing the
sms received
}
}
// structure of the sms listenning program
public class sms
{
String listen()
{
String sms_recieved = // incoming sms is
recieved here

return sms_recieved;

}
}

if any one can help me to implement it through java thread so that no
deadlock occurs.

thanks and regards
Arunesh

Peter Duniho

unread,
Dec 1, 2009, 1:43:34 PM12/1/09
to
focode wrote:
> i am a j2me programmer and facing some problem , problem statement is
> as follows ..
>
> i have "main" java program usually called as midlet , and several
> other java programs which is called by the main program to perform
> several task such as sending and receiving sms etc.
>
> my main program send sms to a particular number eg "53030" and waits
> for sms to be received in the j2me application , sms comming from
> server takes some time , in the mean time , my application is hanged ,
> and as soon as the sms is received , hanging problem or deadlock
> situation come to an end , if i use threads i think this problem will
> be eliminated , i need suggestion as to how to implement thread and
> eliminate my problem .
>
> [...]

> if any one can help me to implement it through java thread so that no
> deadlock occurs.

To be clear: no deadlock is occurring now, based on your description.
All that's happening is that a method known to block until it completes
is being called. Deadlock is a very specific, generally-unrecoverable
situation.

Unfortunately, you're not specific about the nature of the main thread
being blocked by this method call. I gather from your "j2me" comments
that this is Java running on a mobile device ("micro edition"). Is that
correct?

If so, I don't have any first-hand experience on the topic, but Google
quickly found me this article:
http://developers.sun.com/mobility/midp/articles/threading/

As near as I can tell, in a MIDlet you have access to the same Thread
class available in regular Java apps. I don't know whether the
java.util.concurrent.Executors is available to MIDlets, but if so it
offers another very useful way to implement threading.

One significant difference, at least if the above article is correct, is
that a MIDlet doesn't have the a requirement that UI operations (e.g.
setting the current form, updating text, etc.) have to be executed on
the system thread running your main MIDlet code. Instead, from your own
thread code, you can just manipulate the UI as you like and it will work.

Of course, if you have multiple threads manipulating the UI, you need to
coordinate that. But at least you don't have to worry about using
something like invokeLater() like you would for a Swing app.

Anyway, that's a long way of saying: it appears that Google has the
answer to your question. You should probably read up on what Google
says first, and then if you have specific questions you need help with,
post those here.

Pete

Roedy Green

unread,
Dec 4, 2009, 8:24:01 PM12/4/09
to
On Tue, 1 Dec 2009 06:56:25 -0800 (PST), focode
<program...@gmail.com> wrote, quoted or indirectly quoted someone
who said :

I think all you are trying to do is put this code in the background so
that nothing ties up while it waits for a response.

See http://mindprod.com/jgloss/thread.html

I suspect you are using the word "deadlock" in some non-standard way:

See http://mindprod.com/jgloss/deadlock.html
--
Roedy Green Canadian Mind Products
http://mindprod.com
I mean the word proof not in the sense of the lawyers, who set two half proofs equal to a whole one, but in the sense of a mathematician, where half proof = 0, and it is demanded for proof that every doubt becomes impossible.
~ Carl Friedrich Gauss

0 new messages