Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #5375

Re: Basic program flow

From Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid>
Newsgroups comp.lang.java.gui
Subject Re: Basic program flow
Date 2013-10-03 07:51 +0200
Organization A noiseless patient Spider
Message-ID <l2j0lj$3nd$1@dont-email.me> (permalink)
References <l2e6ve$557$1@dont-email.me> <1ab3peylzbmhj.1xz6jwgd30hz0.dlg@40tude.net>

Show all headers | View raw


On 2013-10-01 12:44, Joerg Meier allegedly wrote:
> On Tue, 01 Oct 2013 05:08:45 -0500, Christopher Pisz wrote:
> 
>> What is going on, as I debug through the static main method, my window 
>> is created and it is displayed, and responds. Yet, the debugger steps 
>> out of main...Which I would think exits the program.
> 
> AWT and Swing live on their own threads. frame.setVisible(true); starts the
> AWT event thread, which continues to run after main exits, until all
> visible components are disposed of.
> 
>> Did I make a new thread when I created a frame? If so, at what point? 
>> Why doesn't the program exit after main is done? What keeps it alive? 
> 
> I hope all of those got answered above.

Just to elaborate a bit:

The runtime of the Java Virtual Machine (JVM) is based on the lifetime
of threads.

There are two types of threads: daemon threads and non-daemon threads
("daemon" being basically a boolean flag determined at thread creation
time and before thread start time).

The JVM terminates when its last active non-daemon thread terminates.

Starting the JVM using the OS's executable starts a non-daemon thread
that executes the designated "main" method. That threads terminates when
the "main" method exits.

Starting a visual component, like the AWT Frame, starts a non-daemon
thread called "AWT Dispatch Thread". That thread runs until the last
visual component of the specified category is disposed (to keep things
simple).

(What I'm trying to say is that what you are witnessing is not specific
to applications with visual components, but rather a particular case of
Teh Jav's general rules).

HTH.

-- 
DF.

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Basic program flow Christopher Pisz <cpisz@austin.rr.com> - 2013-10-01 05:08 -0500
  Re: Basic program flow Joerg Meier <joergmmeier@arcor.de> - 2013-10-01 12:44 +0200
    Re: Basic program flow Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-10-03 07:51 +0200
  Re: Basic program flow markspace <markspace@nospam.nospam> - 2013-10-01 09:17 -0700
    Re: Basic program flow Lew <lewbloch@gmail.com> - 2013-10-17 16:55 -0700
  Re: Basic program flow Jeff Higgins <jeff@invalid.invalid> - 2013-10-01 13:00 -0400
  Re: Basic program flow Roedy Green <see_website@mindprod.com.invalid> - 2013-10-01 21:47 -0700

csiph-web