Page 1 of 1

About Question enthuware.ocpjp.v7.2.1382 :

Posted: Wed Apr 02, 2014 12:41 am
by tn1408
Hello,

If the question asks how many running threads are there in this program when run, would it be 3 (main, tc, and the thread created with tc.new Runner())?
Or would it be 2: main and the thread created with tc.new Runner() ?

Thanks,

Tony,

Re: About Question enthuware.ocpjp.v7.2.1382 :

Posted: Wed Apr 02, 2014 12:46 am
by tn1408
Never mind

I got it, using Thread.activeCount()
Thanks,

Tony,

Re: About Question enthuware.ocpjp.v7.2.1382 :

Posted: Thu May 22, 2014 7:30 am
by Elmcrest
@Tony: Thread.activeCount() returns 2 because only one of the two created Thread objects is actually started. (the other one is the main thread)

Besides that, I'm still not sure about this question and the correct answer "2". Isn't the main thread a Thread object which is created automatically for you each time you start a java application? And wouldn't you have to count this Thread instance too, the correct answer therefor being "3"?

Kind regards

Re: About Question enthuware.ocpjp.v7.2.1382 :

Posted: Thu May 22, 2014 7:47 am
by admin
You are right. The main thread is also a thread. But that is not the only thread created automatically. THe JVM could create other threads also for example a GC thread.
The question is asking about the threads created by the program. The problem statement has now been updated to make it clear.

thank you for your feedback!
Paul.