I am using linux-jdk 6 (update 2) on freebsd... all my other code runs
fine (all non-GUI) but this little snippet opens the JFrame then
immediatly closes it and exits:
import javax.swing.JFrame;
public class Main
{
public static void main(String[] args)
{
JFrame frame=new JFrame();
frame.pack();
frame.setVisible(true);
while(true)
;
}
}
Arne Vajhøj - 21 Sep 2007 00:10 GMT
> I am using linux-jdk 6 (update 2) on freebsd... all my other code runs
> fine (all non-GUI) but this little snippet opens the JFrame then
[quoted text clipped - 15 lines]
> }
> }
It should not.
A featured to automatically terminate program that are busy
waiting sounds as a very sophisticated JVM.
Arne
Daniel Pitts - 21 Sep 2007 00:14 GMT
> > I am using linux-jdk 6 (update 2) on freebsd... all my other code runs
> > fine (all non-GUI) but this little snippet opens the JFrame then
[quoted text clipped - 22 lines]
>
> Arne
Perhaps the kernel itself detects the busy-wait and kills the
process. I know I would if I were a kernel.
Aryeh M. Friedman - 21 Sep 2007 00:19 GMT
> > > I am using linux-jdk 6 (update 2) on freebsd... all my other code runs
> > > fine (all non-GUI) but this little snippet opens the JFrame then
[quoted text clipped - 25 lines]
> Perhaps the kernel itself detects the busy-wait and kills the
> process. I know I would if I were a kernel.
Regardless like other people said unless I have dispose_on_close or
exit_on_close it shouldn't matter.... I am attempting to rebuild the
JDK because I installed it under xorg 7.2 but then upgraded to 7.3
(one of the larger upgrades X has ever had)
Daniel Pitts - 21 Sep 2007 00:12 GMT
> I am using linux-jdk 6 (update 2) on freebsd... all my other code runs
> fine (all non-GUI) but this little snippet opens the JFrame then
[quoted text clipped - 16 lines]
>
> }
Works fine for me, but I would suggest NOT using the "while(true)"
Simply allowing your main to exit should be fine, the window will
remain open, and the program will continue to run.
I strongly suggest calling
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); though. This
will allow your program to exit when all the open windows have been
closed.
Roedy Green - 21 Sep 2007 03:27 GMT
On Thu, 20 Sep 2007 22:58:33 -0000, "Aryeh M. Friedman"
<Aryeh.Friedman@gmail.com> wrote, quoted or indirectly quoted someone
who said :
> while(true)
> ;
This is just ties up the main thread and wastes CPU. nothing can get
done.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Andrew Thompson - 21 Sep 2007 05:56 GMT
>I am using linux-jdk 6 (update 2) on freebsd... all my other code runs
>fine (all non-GUI) but this little snippet opens the JFrame then
>immediatly closes it and exits:
Other people have made comment about removing the
while(true) construct.
Beyond that, I am curious as to whether this behaviour
can be reproduced in an AWT based Frame. If not, you
might try using SwingUtilites.invokeLater() to construct
and kick off the *JFrame*. I cannot immediately explain
why lack of doing so would cause the behaviour you are
seeing, but it might be worth trying.

Signature
Andrew Thompson
http://www.athompson.info/andrew/