• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Problem with openDataInputStream

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody,
my problem is that when i establish an Http connection from my midlet to a servlet which has to perform various operations before returning the response, the application seems to hang up (the midp.exe process consumes up to 99% of the machine�s CPU).
I �ve been testing the app and when the openDataInputStream method is invoked, the problem comes up. The app "stops" here until all the data is received, and the stream is closed.
If the same url is invoked from my MS Explorer, i have no problem with the servlets and other Java classes which are executed (here there is no stream opened).
Does anybody know how can I solve this problem, because all my app is slowed down because of this problem.
Thanks.
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you testing on the simulator or on the actual device(and what kind of device)? Can you post your code? If you are testing on the device, can you also tell which device you are using and which way you are monitoring the application's resource consumption?
Liang
 
Alberto Alvarez
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I�m testing the app on the simulator and I�m using the latest version of the j2mewkt 1.0.3 with jdk 1.3.1
To monitorize the process I�m using window�s task administrator. Here is my code sample:

public String sendGetRequestOutput()
{
//variables
String parametros="";
DataInputStream iStrm =null;

//sacamos parametros de la hash para montar la url
try
{
if (htParam != null)
{
Enumeration eClaves = htParam.keys();

while (eClaves.hasMoreElements())
{
String clave = (String)eClaves.nextElement();
String value = (String)htParam.get(clave);

parametros += clave + "=" + value + "&";

}
parametros = parametros.substring(0,parametros.length()-1);
}//if
}// try
catch (Exception e)
{
System.out.println("[SetHttpConnection] Error al extraer datos de tabla hash: " +e);
}

if (url.equals(""))
{
url=URL;
}

try
{
url += servletName + "?" + parametros;

http = (HttpConnection)Connector.open(url);

http.setRequestMethod(HttpConnection.GET);

http.setRequestProperty("User-Agent","Profile/MIDP-1.0 Configuration/CLDC-1.0" );

http.setRequestProperty("Accept","text/plain");

iStrm = http.openDataInputStream();

if (http.getResponseCode()== HttpConnection.HTTP_OK)
{
StringBuffer b = new StringBuffer();
int ch;
while ((ch = iStrm.read()) != -1)
{

b.append((char) ch);
}
return b.toString();
}
else
{


return null;
}
}//try
catch(Exception e)
{
return null;
}
finally
{
try
{
if (http != null)
{
http.close();
}
if (iStrm != null)
{
iStrm.close();

}
}
catch(Exception e)
{
System.out.println("[SetHttpConnection] Error al cerrar conexion http " +e);
}


}

}
Please help me,
thanks.
 
Alberto Alvarez
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, in the j2mewkt 1.0.3 the process is called zayit.exe
 
liang gu
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, first I like to have a clear understanding of the problem you are facing. Are you saying that: the HTTP connection from MIDLet to servlet takes a very long time, while with the same URL the connection time from IE browser to servlet is much less?
If this is the case, I will suggest you to read the input stream into a big buffer instead of reading it one character by one character. I have experienced dramatic difference in HTTP connection time.
 
Alberto Alvarez
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you understood correctly the question. Now my doubt is how do I manage with a big buffer, rather than reading character by character? I would be very pleased if you showed me an example.
By the way, I have deduce that the problem is the openDataInputStream�s implementation. I think it falls in a infinitive loop, while waiting for data. This is the cause of the process�s CPU consume problem. My problem is that if this is true, I don�t know how to solve it.

 
Water! People swim in water! Even tiny ads swim in water:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic