• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

doubt regarding threads

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
NagarajGoud uppala
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic