aspose file tools*
The moose likes Java Micro Edition and the fly likes how to stop a thread in j2me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "how to stop a thread in j2me" Watch "how to stop a thread in j2me" New topic
Author

how to stop a thread in j2me

amal shah
Ranch Hand

Joined: May 05, 2006
Posts: 92
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

Joined: Jan 11, 2006
Posts: 160
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.


Rashid Mayes
http://www.hostj2me.com/ - http://www.worlddeveloper.org/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to stop a thread in j2me