• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to stop a thread in j2me

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic