• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to stop a thread in j2me

 
amal shah
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
my aim is to get an image from the server...
this is how i do it:
public void getimage(String url) throws IOException
{
HttpConnection conn = null;
InputStream is = null;
int read=-1;
StringBuffer b=null;
try
{
conn = (HttpConnection)Connector.open(url);
is = conn.openInputStream();
b = new StringBuffer();
while ((read = is.read())>=0)
{
b.append((char)read);
}
image=Image.createImage(((b.toString()).getBytes()),0,((b.toString()).length()));
}
catch(SecurityException e)
{
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
if (is != null)
is.close();
if (conn != null)
conn.close();
}
}

now what i do is...to get an image i start a Thread...
now the thread has already started...and say for example the user wants to stop the process of getting the current image...and wants to download another image....so the thread will start again...in such a case i would like the earlier process of getting the image to stop....but am not able to get through...
(J2ME DOSEN'T HAVE THE stop() METHOD)....

help appreciated

cheers
amal shah
 
Rashid Mayes
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well you are not supposed to use stop in SE either. To answer you question, you will have to implement the shutdown process yourself.

Try reading this article.

http://developers.sun.com/techtopics/mobility/midp/articles/threading2/

It should give you everything that you need.

Also please review you code and how you are reading from the stream. In addition please see the ByteArrayOutputStream. There is also a method to create an image from a stream.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic