File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help me..............

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator

Are they real exam question???
I am sorry really ,but i don't knw that,
and i get it from: http://www.deping.net/cgi-bin/lbbs/topic.cgi?forum=4&topic=436
------------------

[This message has been edited by Lhy Killers (edited July 19, 2001).]
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
Why no one help me to solve the examination question???
 
Dave Vick
Ranch Hand
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lhy Killers:
Why no one help me to solve the examination question???

Because you didn't even wait two hours for an answer!!
On your first question:
The two that can't directly stop a thread from executing are notify and notifyAll. Of the others:
Yield will at least temporalily halt the thread, it may be restarted right away by the scheduler. wait will cause the thread to wait until it receives a notify or notifyAll. And if the thread is already running then calling start on it will throw an IllegalThreadStateException.
notify and notifyAll can not directly cause the thread to stop, but if the thread calling them doesn't have the lock on an object they'll throw an IllegalMonitorStateException when the try to call one of those two.
Given the way the question is worded it may have been done better or given little more info.
Hope that helps
Dave
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
Why not select 5>???
The NO.5 directly cause a thread to stop executing?
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lhy Killers:
Why not select 5>???
The NO.5 directly cause a thread to stop executing?

start() CAN stop the current thread from executing.When you start a thread you request the ThreadScheduler to start another lightweight process.Although it seems to us that the ThreadScheduler runs many Threads in parallel, actually one Thread is run at a time.Hence the ThreadScheduler has to stop one Thread to execute another.The time for execution would be so small that we feel that many threads are running simultaneously.
Hope this helps,
Sandeep
SCJP2, OCSD (JDeveloper), OCED(Oracle Internet Platform)
[This message has been edited by Desai Sandeep (edited July 19, 2001).]
 
Dave Vick
Ranch Hand
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
desai
Is right I didn't read the answer for #5 completely. It says calling start on another object. And it is correct calling start on another object will not directly cause the current thread to stop. I thought it said if you call it on the currently running thread. That's what I get
Dave
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
But there are two correct answers ,not three,
how could i select which two???
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The question is about what CANNOT stop; not what CAN!The Thread.start() CAN!
So the answers are 3 (notify) and 4(notifyAll)
-- Sandeep
 
Dave Vick
Ranch Hand
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would be inclined to say that calling start on another object cannot directly cause a thread to stop. Even if the thread has a higher priority it is system dependent and it may or may not cause the current thread to stop.
I think it is a poorly worded question. When they say 'cause a thread to stop' I am assuming they mean the currently executing thread. On answers 1 - 4 I assume they mean they current object. I know its dangerous to assume but...
So, calling start on another object would also be a valid answer.
Anyone else have an opinion or the definitive answer??

Dave
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
I am puzzled about that..
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave,
We know one thing for sure that when you call the Thread.start() method, you are passing the control to Thread scheduler.Also we know the way the Thread scheduler functions - i.e, it executes one thread at a shortest possible time, giving us a picture that the two threads ae executing simultaneously.
Instead of making the assumption that the question is asking you whether "the current thread" stops, we can talk in generic terms - one of the threads (which is already started) will get effected; i.e, either the thread that has been started has to STOP from running or the Thread that is been running is stopped by the Thread scheduler to allow the new started thread to run.So, in either case Thread.start() CAN stop a thread from executing.
Hope this helps,
Sandeep
[This message has been edited by Desai Sandeep (edited July 20, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic