| Author |
Daemon
|
Simon Cockayne
Ranch Hand
Joined: Dec 09, 2000
Posts: 214
|
|
Hi, How much do I need to know about setDaemon Thread method, for the exam? I just came across it for the first time in second sun ePractice exam. I had never seen it before and have no idea what it does. Off to look at the API.. Cheers, Si.
|
SCJP 1.4 (93%)<br />SCJD (In progress. It can run, but it can't hide...)
|
 |
Jeff Bosch
Ranch Hand
Joined: Jul 30, 2003
Posts: 804
|
|
Hi, Simon - Are you sure you took the right practice exam? This sounds more like a J2EE question to me...
|
Give a man a fish, he'll eat for one day. <br />Teach a man to fish, he'll drink all your beer.<br /> <br />Cheers,<br /> <br />Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
I do recall a daemon question on my SCJP 1.4 exam. The main thing you need to know is that a running daemon thread will not prevent a program from quitting. In other words, as soon as all the non-daemon threads are done, the program will quit. You can determine whether a thread is a daemon by calling isDaemon(), which returns a boolean. And you can make a thread a daemon or non-daemon by calling setDaemon(boolean b).
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Simon Cockayne
Ranch Hand
Joined: Dec 09, 2000
Posts: 214
|
|
Hi Jeff, Now is not the time to be telling me I have been revising/practising the wrong stuff! The Sun ePractice exam was in the bundle: "WGS-PREX-J035C: ePractice Certification Exam for the Sun Certified Programmer for the Java 2 Platform 1.4 (180 day subscription) ". The exam name is "WGS-PREX-J035B-Form2: Sun Certified Programmer for the Java 2 Platform 1.4". This is the right thing...right? Cheers, Si.
|
 |
Simon Cockayne
Ranch Hand
Joined: Dec 09, 2000
Posts: 214
|
|
Marc, Is main a user or a daemon thread? I know I can check, but I am running out the door and I don't want to forget... Anywise, if a question is asking if a progam will termintate (which I have seen several of) then: 1) If the program involves nothing other than the main thread and that thread's logic completes, the program will terminate. 2) If the program involves nothing other than the main thread and its logic is looping/blocking endlessly, tjhe program will NOT terminate. 3) If the program starts an additional user (not daemon) thread in addition to main and that the additional thread's logic completes, the program will terminate, assuming main thread terminates. 4) If the program starts an additional user (not daemon) thread in addition to main and that the additional thread's logic is looping/blocking endlessly, the program will NOT terminate, regardless of whether the main thread terminates. 4) If the program starts an additional daemon thread in addition to main and that additional daemon thread's logic completes, the program will terminate, assuming main thread terminates. 5) If the program starts an additional daemon thread in addition to main and that the additional daemon thread's logic logic is looping/blocking endlessly, the program will STILL terminate, assuming main thread terminates. Oh and I see it causes a runtime error if you try to call setDaemon on a live thread. I appreciate your feedback Marc. Cheers, Si.
|
 |
Simon Cockayne
Ranch Hand
Joined: Dec 09, 2000
Posts: 214
|
|
Hi, I have discovered that the "main" thread is not a Daemon thread. Using Thread.currentThread().isDaemon() in main method, which returns false. Cheers, Si.
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Si, I believe your summary points above are all correct.
|
 |
amit taneja
Ranch Hand
Joined: Mar 14, 2003
Posts: 806
|
|
didn't able to understand all 5 points... please explain me last 3 pts.. i.e 3,4,5
|
Thanks and Regards,<br />Amit Taneja
|
 |
Jeff Bosch
Ranch Hand
Joined: Jul 30, 2003
Posts: 804
|
|
Hey, Simon - Maybe I slept through that part! I don't remember any daemon thread topics in any of my studies for the exam or in any of the mock exams or in the real exam. Vewy Intewesting, as Elmer Fudd would say...
|
 |
nagaraj reddy
Ranch Hand
Joined: Feb 21, 2005
Posts: 43
|
|
Hi simon please explain and compare the 4 && 5 points you listed above yhanks in advance
|
 |
 |
|
|
subject: Daemon
|
|
|