aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt regarding threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt regarding threads" Watch "doubt regarding threads" New topic
Author

doubt regarding threads

NagarajGoud uppala
Ranch Hand

Joined: Nov 13, 2008
Posts: 86
Hi,
This is from k&b threads,selftest(pgno:768,qno:13)

1.new Starter().run();
2.new Starter().start();
3. new Thread(new Starter());
4. new Thread(new Starter()).run();
5. new Thread(new Starter()).start();

if we place the above statements at line 1 in code which is true?
answers are:
c.only one might produce the output 4 2
d.exactly two might produce the output 4 4

my doubt is how can we find out the answer ? i run the above code
for 4 i got output-- 1 1
for 5 i got output--1 8

i am using 1.6 version. i am confusing which is correct ? how?
please any body explain me step wise


I know Life is very Tough...But I AM TOUGHER
SCJP 1.5
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

my doubt is how can we find out the answer ? i run the above code
for 4 i got output-- 1 1
for 5 i got output--1 8

i am using 1.6 version. i am confusing which is correct ? how?
please any body explain me step wise


I think that you are misinterpreting the questions here. The "2" and "4" aren't (or may not be) the actual numbers. The significance is whether the numbers are the same or different -- meaning whether or not the code is being run by the same thread or different thread.

Henry

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
NagarajGoud uppala
Ranch Hand

Joined: Nov 13, 2008
Posts: 86

I think that you are misinterpreting the questions here. The "2" and "4" aren't (or may not be) the actual numbers. The significance is whether the numbers are the same or different -- meaning whether or not the code is being run by the same thread or different thread.

Henry

Hi Henry,
Thanks for giving some clarity.you mean if the same thread is run it,the numbers will be same and if the different thread run it numbers will be different. isn't it??
if my understanding is wrong please correct me
 
Don't get me started about those stupid light bulbs.
 
subject: doubt regarding threads