This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Daemon

 
Simon Cockayne
Ranch Hand
Posts: 214
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Simon -

Are you sure you took the right practice exam?

This sounds more like a J2EE question to me...
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Simon Cockayne
Ranch Hand
Posts: 214
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 214
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 214
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Si, I believe your summary points above are all correct.
 
amit taneja
Ranch Hand
Posts: 813
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
didn't able to understand all 5 points...


please explain me last 3 pts.. i.e 3,4,5
 
Jeff Bosch
Ranch Hand
Posts: 805
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi simon

please explain and compare the 4 && 5 points you listed above



yhanks in advance
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic