• Post Reply Bookmark Topic Watch Topic
  • New Topic

Program doesn't terminate itself  RSS feed

 
Harish Kashyap
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • 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
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • 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
 
Mo Ibrahim
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!