David Blankley wrote:
>
> I haven't tested under 1.2 yet, but a similar problem exists in v1.1.7
>
> Maybe I'm misunderstanding threads, but the following code will go through
>the run method once and exit:
You're probably misremembering a bit... this example shouldn't go
through run() any more than once.
I now remember dealing with something similar early in my Java (and
Blackdown) experience, although I cannot reproduce it now. Something
like this:
---------------------------------------------------
import java.awt.*;
public class Hello extends Thread
{
public void run()
{
(new Frame("Hello World")).setVisible(true);
}
public static void main(String[] argv)
{
(new Hello()).start();
}
}
---------------------------------------------------
would sometimes exit without ever showing a window. I fixed it by adding
some synchronization to ensure that main() wouldn't exit before the
other thread had done a certain amount of processing, but that sounds a
bit klugey in hindsight. There may be an issue here of Bad Programming
Practice (relying on unspecified thread behavior), but I'm not entirely
convinced of that.
Nathan
> Unfortunately, I'm doing this code from memory so it might not be perfect...
>
> import java.net.*;
> public class ThreadEg implements runnable {
> private Thread myThread;
>
> public ThreadEg() {
> myThread = new Thread(this);
> myThread.start();
> }
>
> public void run() {
> System.out.println("inside the run statement...");
> }
>
> public static void main(String [] args) {
> ThreadEg threadEg = new ThreadEg();
> }
> }
>
> This results in the sample output
> Inside the run statement...
> Being displayed once.
> The program was executed with green threads.
>
> Dave
> ----------
> From: Nathan Meyers [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, July 08, 1999 10:50 AM
> To: Rob Nugent
> Cc: [EMAIL PROTECTED]
> Subject: Re: Java3D and 'main()'
>
> Rob Nugent wrote:
> >
> > Many thanks to everyone who answered me on this issue. Nathan managed to put me on
>the
> > right track:
> >
> > The window was indeed visible until main() exited (I think I neglected to say this
>in my original post).
> >
> > I was running with jdk1.2pre1 with green threads. Moving to native threads solved
>the problem, although
> > I can' explain why. This is a good enough solution for me until I can move to
>RedHat60/glibc2.1/jdk1.2pre2
> >
>
> This is comforting in a troubling sort of way :-). I had hoped moving to
> green threads would solve the problem, and ended up having it backwards.
> Apparently, the AWT threads are being started... yet the application
> terminates when the main thread ends. Sounds buggy to me. Has anyone had
> an opportunity to try this under pre2?
>
> Nathan
>
> ----------------------------------------------------------------------
> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
>
> ----------------------------------------------------------------------
> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]