Hi, I was wondering why some of my programs are daemons and some not. for example, I created this class that executes commands on my other computer like ssh but without the security the structure is somewhat like this
nowhere in that class have i called Thread.setDaemon(true), but it still wont show itself on run. this other class I made recently basically has the same structure but won't run as a daemon. I tried extending thread and setDaemon( true ) before start() but it wont hide. It implements ImageObserver and utilizes the Robot class. Thats the only big difference I can see between the two classes. Does anyone have any ideas about why my later class wont hide? I would also be interested in why my first class is a daemon when I didn't even ask it to be. I can post the code if neccessary. Thanks.
Edit: just tested the later class on windows XP and it is a daemon. not so on mac OS X. im confused. does apple change their version of the VM so much that it would do that? maybe apple thought Robot and daemon are a bad combination? or imageobserver expects you to display something anyways? [ December 06, 2004: Message edited by: Alex Wolf ]
First, note that setDaemon() has nothing to do with the UNIX definition of a "daemon process." setDaemon(true) marks a Thread such that the Thread's existence won't stop the JVM from exiting; i.e., if all Threads in a JVM are daemon threads, then the JVM will exit.
It has nothing to do with being connected to a terminal, running in the background, etc, on any platform.
Now, as far as your question goes: the Swing event thread is not a daemon thread. If you do something which starts the event thread (like use java.awt.Robot at all, on most implementations, anyway) then your program won't exit just because main() returns.
But this is an implementation detail. There's nothing in the spec that says anything about what will and will not start the event thread. So it's completely possible that in one JVM, your program will exit, and on another, it won't. If you need to program to exit at a particular time, then simply call System.exit().