• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I neeed answers for these

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Multithreading may be correctly accomplished in Java in which of the following ways?

a)Extend the Thread class, provide an implementation for the start method and create an instance of this new subclass
b)Create a class which implements the Threadable interface, and pass an instance of this class to a Thread Class constructor
c)All of the above
d)None of the above

Locking is the main mechanism for restricting simultaneous thread access to specific java code. Which of the following statement(s) are true regarding locks / monitors?
a)One lock / monitor is associated with each Class
b)One lock / monitor is associated with each Synchronized block
c)One lock / monitor is associated with each Thread
d)One lock / monitor is associated with each Object
e)All of the above
With respect to User and Daemon threads:
a)Daemon threads can not be destroyed
b)Running User threads prevent a Java VM from exiting
c)Running Daemon threads prevent a Java VM from exiting
d)Daemon threads can not be grouped together
e)The Java VM will exit when no non-daemon threads are running
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think
Answer for Q)1 is b)
for Q)2 is b
for 3) is a) b)
 
Trailboss
Posts: 23780
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q1) d - there is no "Threadable interface". There is a Thread class and a Runnable interface. And you don't implement the start() method, you implement the run() method.
Q2) a, b and d
Q3) c
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
This message was posted here long back.Today I had gone through this.
1.With respect to User and Daemon threads:
a)Daemon threads can not be destroyed
b)Running User threads prevent a Java VM from exiting
c)Running Daemon threads prevent a Java VM from exiting
d)Daemon threads can not be grouped together
e)The Java VM will exit when no non-daemon threads are running .
Answer given by paul is c.But I think the answer for this is b.
2.Locking is the main mechanism for restricting simultaneous thread access to specific java code. Which of the following
statement(s) are true regarding locks / monitors?
a)One lock / monitor is associated with each Class
b)One lock / monitor is associated with each Synchronized block
c)One lock / monitor is associated with each Thread
d)One lock / monitor is associated with each Object
e)All of the above
For this paul has given the answers as a, b and d.
But I had read somewhere that the lock is only associated with synchronized block.
Can anyone throw somelight on this to help me with explanation.
Thanks and regards
Sunita
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think,
1.When Last of the Non-Deamon thread stops, JVM exits. hence, ans is B.
2. There is lockk available for Synchronized Block, an object & a class. So a,b d is correct.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
2. I think the that lock is only associated to object and class.In synchronize block also u have to specify an object whose lock will be obtained before executing the block.
So answer should be only object and class.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think
Ans for 1st question is d (i.e none of the above)
Ans for 2nd question is d (i.e. lock is associated with each object not even class).
Ans for 3rd question is b
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I agree with Puneet. Locks/Moniters are associated with only
Objects and Classes.
If a class has many Synchronized methods, it doesnt mean that is has many locks. There is only one lock associated with the object. so when one synchronized method is executing, another synchronized method cannot be executed.
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a very old post. But today I came across this.
My answer is 1.d
2.d lock associated with object
3.b Runnnind User thread prevennts JVM to exit.
Am I write?
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the answers are:
1.D
2.B,C,D
3.B,E
Are they correct ?
[ May 31, 2002: Message edited by: geetha nagarajan ]
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) D
2) It depends on what "lock association means".
In Java we could use the lock of any object to syncronize a method or block. Because classes and threads in the JVM are objects it is possible to use their locks also.
You can consider, as well, the lock of an object associated with the method or block is guarding.
The answers, thus, vary due to the meaning of the association term you chose. Not a good question for the exam I'm afraid.
3) B unles one of them executes System.exit(0)
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shan:
Multithreading may be correctly accomplished in Java in which of the following ways?
a)Extend the Thread class, provide an implementation for the start method and create an instance of this new subclass
b)Create a class which implements the Threadable interface, and pass an instance of this class to a Thread Class constructor
c)All of the above
d)None of the above


The answer is D. You don't override start, you override run and there is no Threadable interface. Rather, you could implement the Runnable interface.

Originally posted by Shan:

Locking is the main mechanism for restricting simultaneous thread access to specific java code. Which of the following statement(s) are true regarding locks / monitors?
a)One lock / monitor is associated with each Class
b)One lock / monitor is associated with each Synchronized block
c)One lock / monitor is associated with each Thread
d)One lock / monitor is associated with each Object
e)All of the above


This one's rather fuzzy. A and D are obviously correct. However, I believe that you could have more than one lock associated with a thread or a synchronized block. For example, let's say that a thread calls a synchronized method on an object. That thread will then obtain that object's lock. Now, suppose that, inside that method, a synchronized method is invoked on another object. The thread also gains the lock for that object. The thread has now acquired two locks. You can create a similar example for a synchronized block. Therefore, the answer should be A & D.
However, I came to this solution by making an assumption about how the exam uses the word "Thread." If the exam intended a Thread to be the Java class Thread or an instance of that class, then, just like answers A & D, there would be one lock associated with a Thread. That's where the question becomes fuzzy.
I would say that the answer should be A & D.

Originally posted by Shan:

With respect to User and Daemon threads:
a)Daemon threads can not be destroyed
b)Running User threads prevent a Java VM from exiting
c)Running Daemon threads prevent a Java VM from exiting
d)Daemon threads can not be grouped together
e)The Java VM will exit when no non-daemon threads are running


The answer is B. You could have multiple non-daemon threads that aren't running but are "alive." Until all of these threads are terminated, the JVM will continue to run.
I hope that helps,
Corey
[ May 31, 2002: Message edited by: Corey McGlone ]
 
Swati Gupta
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jose and Corey
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shan:
With respect to User and Daemon threads:
a)Daemon threads can not be destroyed
b)Running User threads prevent a Java VM from exiting
c)Running Daemon threads prevent a Java VM from exiting
d)Daemon threads can not be grouped together
e)The Java VM will exit when no non-daemon threads are running


In option b, Running User threads could call System.exit() and terminate the program and JVM. So, I think the answer should be 'e', according to JLS 12.8.
I am wondering about option a: deamon threads can not be destroyed. They can not be???

JLS 12.8 Program Exit
A program terminates all its activity and exits when one of two things happens:
* All the threads that are not daemon threads terminate.
* Some thread invokes the exit method of class Runtime or class System and the exit operation is not forbidden by the security manager.


-Shiva
ps: was reviewing all the old posts regarding threads to test my threads basics
 
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do we have to know the details about hat a User Thread is and what a Daemon thread is? i didn't know we had to, the book i am studying has mentioned nothing about User or Daemon in this context.
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nally posted by Jasper Vader:
Do we have to know the details about hat a User Thread is and what a Daemon thread is? i didn't know we had to, the book i am studying has mentioned nothing about User or Daemon in this context.
I think everything you need to know about daemon and user threads is on this page already : )
So, you should understand the basic idea and pay atttention to what Corey wrote and you'll have everything you need.
Cheers,
Kathy
"To be remembered, it must be memorable."
[so when you're studying, find a way to make this stuff interesting, exciting, strange, shocking, ANYTHING that makes your brain wake up and pay attention.]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic