Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jun 2008

    Question How to avoid potential deadlock and perform in different thread.

    Tools:I have midlet with Visual Form, named form and form1
    - form i used to take the informations from user nothing more.
    - form1 is the SIP register on load, button call connect, button hangup.
    - S40 emulator for cldc
    - S60 emulator for cldc
    - Sun cldc emulator

    Problem: - when form1 load under S40 emulator and in Sip server, i see registered successfully.
    - when the same code i test in S60 emulator, the time it load form1, whole emulator crash close, server i dont see any registration log.
    - the same code when i test with NetBeans cldc emulator, it show
    Warning: To avoid potential deadlock, operations that may block, such as networking, should be performed in a different thread than the commandAction() handler.

    // Form1 Load
        public Form getForm1() {
            if (form1 == null) {
                form1 = new Form("Test", new Item[] { getImageItem1(), getImageItem2(), getTo() });
                fRegister(); // This is the Big problem...
            return form1;
        // data send/recv
        public void fRegister(){
            try {
                rtpCon = (UDPDatagramConnection) Connector.open("datagram://:");
                sdpPort = rtpCon.getLocalPort();
                provider = new SIPProvider(UserName,passwd,SipServerIP, SipServerPort, 1225);
           } catch (Exception ex1) {
        // Form command
        public void commandAction(Command command, Displayable displayable) {
    	if (displayable == form1) {
                if (command == exitCmd) {
    		// Exit
                } else if (command == hangupCmd) {
    		// Hangup
                } else if (command == sendCmd) {
    		// Send

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Rome, Italy

    Re: How to avoid potential deadlock and perform in different thread.

    Hi shamun.toha,

    as the warning itself says, you should avoid performing blocking operations in the main application thread. Instead, you should use a separate Thread for them.

    For some good introductory articles about threading in Java ME, take a look here:



  3. #3
    Regular Contributor
    Join Date
    Apr 2007

    Re: How to avoid potential deadlock and perform in different thread.


    I recommend to you using different threads in your application because of deadlocks; I mean, use a thread to deal with the GUI, the high level of your application; I think it´s possible to difference some deadlock operations :
    - Gui operations
    - Comm operations ( I include http connections, bluetooth connections, etc..., for example, in a bluetooth connection, is required to use a thread to control the connection with the target device and other thread to control the sending of information, if you use the same thread to connect and send, Im sure your application will crash)
    - Sms operations
    - other ones...
    So my advice is to perform every deadlock operation in a different thread, if you make every operation in the main thread, your application will crash or just let the device out of combat.

    ( if you want to know more about threads, go to sun and watch for threads, sync of threads, Runnable, ...etc)

    Kind regards

  4. #4
    Registered User
    Join Date
    Jul 2008

    Re: How to avoid potential deadlock and perform in different thread.

    Hi, to avoid the deadlock, your class must implement the Runnable abstract class, then write your code that may make a deadlock in the override method "run()", or by creating a new object that recived the arguments from the main class over the constructor.

    I think most of communication operations may cause the deadlock, so its need to be in another thread.

    I hope this can help you.

  5. #5
    Registered User
    Join Date
    Jul 2007

    Re: How to avoid potential deadlock and perform in different thread.

    I have the same problem when I try to create a file, I got this solution from someone, and it's work for me:

    new Thread(new Runnable(){
    public void run()
    //your function call
    }catch(Exception e){}

    I hope it'll work for you

Similar Threads

  1. To avoid potential deadlock, operations that may block
    By tieuquai in forum Mobile Java Networking & Messaging & Security
    Replies: 4
    Last Post: 2008-05-12, 22:25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts