Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

Is this a JDK bug?

Thread view: 
Aryeh M. Friedman - 20 Sep 2007 23:58 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:

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/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.