Groups > Symbian > Symbian EPOC Java > One Warning is coming




One Warning is coming

One Warning is coming
Sat, 5 Nov 2005 08:11:34 +0530
Hi Folks,
 In my j2me appln im trying to tranfer a profile(string) using RFCOMM 
between two BT devices.
Even after creating separate classes called BlueServer and BlueClient  and 
started separate threads for sending and receiving profiles , the warning 
for deadlock is still there.Plz have a glance at following sample snippets.
  public void commandAction(Command c,Displayable d){
      if(c==sendProfilecmd){
          blueServer=new BlueServer(this);
          blueServer.start(); //deadlock
      }
  }
Actually inside the run() im calling the method beServer() where all the 
initializations are made.
public void beServer(){
      try {
            device = LocalDevice.getLocalDevice();            // create/get 
a local device
            device.setDiscoverable(DiscoveryAgent.GIAC);
            StringBuffer url = new
StringBuffer("btspp://localhost:");
            url.append(serviceUUIDs[1].toString() + 
";name=BlueTrial;authorize=true;authenticate=true");
            notifier = (StreamConnectionNotifier) 
Connector.open(url.toString());
            record = device.getRecord(notifier);
            boolean isclosed=false;
            while(!isclosed){
                try {
                    serverconn = (StreamConnection)notifier.acceptAndOpen();
                    sendMessage(serverconn);
                } catch (IOException e) {
                    System.out.println("StreamConnection exception" 
+e );continue;
                }
            }
        } catch (Exception e) {
            System.err.println("Can't initialize bluetooth: " + e);
        }
    }
public void sendMessage(StreamConnection serverconn){
          ListProfile lispro=new ListProfile(myp);
          byte[] msgData=lispro.takeProfile();
            try{
                DataElement base = new DataElement(DataElement.DATSEQ);
                record.setAttributeValue(attr[1],base);
            }catch(Exception e){
                System.out.println("recordset" + e);
            }
            OutputStream out = null;
            try {
                out = serverconn.openOutputStream();
                out.write(msgData.length >> ;
                out.write(msgData.length & 0xff);
                out.write(msgData);
            } catch (IOException e) {
                System.err.println("Can't send image data: " + e);
            }
            if (out != null) {            // close output stream anyway0
                try {
                    out.close();serverconn.close();
                } catch (Exception e) {} // ignore
            }else
                System.out.println("out is null");
    }
I tried it with Synchronized block also.Please suggest some tries which i 
can try to avoid Deadlock.
Thanks in advance.
yafy.
Post Reply
View Original Image
about | contact