wood burning stoves 2.0*
The moose likes Java in General and the fly likes class won't daemonize Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "class won Watch "class won New topic
Author

class won't daemonize

Alex Wolf
Greenhorn

Joined: Aug 24, 2004
Posts: 16
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 ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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().

Does this answer your question?


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: class won't daemonize
 
Similar Threads
daemon Vs User Thread
Doubt in Threads????
need clarification on threads
Resizing Large JPG Problem
Question from exam on Daemon thread