• 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

Program doesn't terminate itself

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
i've written this much code in my program
public static void main(String[] arg)
{
Image img = Toolkit.getDefaultToolkit().getImage(arg[0]);
PixelGrabber p = new PixelGrabber(img,0,0,72,14,false);
try{
p.grabPixels(1000);
}catch(InterruptedException e){System.out.println("Interrupted thread :"+e);}
byte[] b = (byte[])p.getPixels();
System.out.println(b.length);
}

it runs perfectly prints the length of array but doesn't terminate untill i force it to.
can anybody tell me what's going wrong.
thanx
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By accessing an Image from Toolkit, you've silently invoked an AWTThread, which monitors and supports graphic activity. This thread is daemon-like, in that it sits around and waits for things to do (repaint screen exposures, and so on).
You get the thread whether you actually have a visible Window or not in this case. You either have to force termination or provide a way for the application to exit on some condition. An explicit System.exit() should do the trick.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike is right.
Did you try a simple return statement at the end of main() ?
I think that should work.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic