Is this a JDK bug?

A

Aryeh M. Friedman

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)
;
}
}
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Aryeh said:
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)
;
}
}

It should not.

A featured to automatically terminate program that are busy
waiting sounds as a very sophisticated JVM.

Arne
 
D

Daniel Pitts

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)
;
}

}

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.
 
D

Daniel Pitts

Aryeh said:
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)
;
}
}

It should not.

A featured to automatically terminate program that are busy
waiting sounds as a very sophisticated JVM.

Arne

Perhaps the kernel itself detects the busy-wait and kills the
process. I know I would if I were a kernel.
 
A

Aryeh M. Friedman

Aryeh said:
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)
;
}
}
It should not.
A featured to automatically terminate program that are busy
waiting sounds as a very sophisticated JVM.

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)
 
A

Andrew Thompson

Aryeh said:
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.

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

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200709/1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top