i got this warning from my j2me code that try to connecto to database using php and httpconnection,,

Warning: To avoid potential deadlock, operations that may block, such as
networking, should be performed in a different thread than the
commandAction() handler.

pls help..

It's suggesting that you use threading to avoid your application from hanging while a process is waiting for resources. For example if you have a mobile IM application for a mobile if you don't use threading and one device trys to send a message but has to wait for resources before it can successfully send the message, no other devices can send a message untill that first device finishes sending it's message. However with threading each device can create it's own session and send the symotaniously.

Have a look at the 'How do i' link on THIS LINK, the subject of the application might not be relevant to your app but it may explain dead lock a bit better.

Hope this helps.

@ChrisHunter you posted generic link

@akuvidz post your code or have look at Beginning J2ME: From Novice to Professional - chapter 10

Yeah sorry there is a link towards the bottom of the link i posted which is about deadlock in mobile development but i cannot access due to banns in work for some reason

I treid too, but there is issue with msdn website as when link clicked page start to load and then suddenly redirect to different section.
Anyway, the above mention book chapter is what all what one needs to do.

i try to use thread in my code,, and it was successfull..

so i tried this code

public void commandAction(Command c, Item item) {
        // TODO Auto-generated method stub

        if(item == login){
            new Thread (this).start();
        }


public void run() {

        String hasil = null;
        String userName = username.getString();
        String passWord = password.getString();


        try {
            hasil = new String(connect.load(userName,passWord));
            Alert alarm = new Alert("LOGIN");
            alarm.setTimeout(Alert.FOREVER);
            alarm.setString(hasil);
            display.setCurrent(alarm);
        } catch (IOException ex) {
            Alert alarm = new Alert("LOGIN");
            alarm.setTimeout(Alert.FOREVER);
            alarm.setString(hasil);
            display.setCurrent(alarm);
        }

    }

it was successfull,,but then, after i login,,i want it to redirect into other class,, whenever i add "if else" after

hasil = new String(connect.load(userName,passWord));

they redirect but didnt detect wrong or not,, even i put wrong id and pw,, they still running to my other class which they shouldnt go,,

this is my ConnectServer code..

    private String url;
    private Form form;

    public ConnectServer(String url){
        this.url = url;
    }

    public byte[] load(String user, String pass) throws IOException{

        byte[] byteBuffer = null;

        HttpConnection hc = (HttpConnection) Connector.open(this.url);
        try {
            hc.setRequestMethod(HttpConnection.POST);
            hc.setRequestProperty("User-Agent",
                    "Profile/MIDP-1.0 Confirguration/CLDC-1.0");
            hc.setRequestProperty("Accept_Language", "en-US");
            //Content-Type is must to pass parameters in POST Request
            hc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            OutputStream os = hc.openOutputStream();
            String userName = "username=" + user;
            String passWord = "&password=" + pass;
            os.write(userName.getBytes());
            os.write(passWord.getBytes());
            if (hc.getResponseCode() == HttpConnection.HTTP_OK) {
                InputStream is = hc.openInputStream();

                try {
                    int len = (int) hc.getLength();
                    if (len > 0) {
                        byteBuffer = new byte[len];
                        DataInputStream dis = new DataInputStream(is);
                        dis.readFully(byteBuffer);
                    } else {
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        byte[] buffer = new byte[512];
                        int count;
                        while ((count = is.read(buffer)) >= 0) {
                            bos.write(buffer, 0, count);
                        }
                        byteBuffer = bos.toByteArray();
                    }
                } finally {
                    is.close();
                }
            }

        } finally {
            hc.close();
        }

        return byteBuffer;
    }

and this is my php code

<?php
 $user = "root";
 $pass = "1234";
 $host = "localhost";
 $db = "lms";

 $conn = mysql_connect($host,$user,$pass);
 mysql_select_db($db);

 if(!$conn){echo"Gagal Koneksi ke Database";}

$flag = false;

if($_POST['username'] != "" and $_POST['password'] != "")
{
 $username = $_POST['username'];
 $password = $_POST['password'];
 $flag = true;
}
else
{
 echo"username dan password harus diisi";
}

if($flag == true)
{
 $sql = "SELECT * FROM employee WHERE emp_other_id = '".$username."' AND emp_password = '".$password."'";
 $hasil = mysql_query($sql);
 $jmlacc = mysql_fetch_array($hasil);

 if($jmlacc > 0)
 {
 echo"valid";
 }else{
 echo"invalid";
 }
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.