Hi,all:
Which of the following is always a result of attempting to compile and run the program?
a. The program compiles and runs without error.
b. The second attempt to start
thread t1 is successful.
c. The second attempt to start thread t1 is ignored.
d. Compiler error at marker 1.
e. An IllegalThreadStateException is thrown at run-time.
f. None of the above
e is correct.
Here is the explaination:
The exam might have a question that invokes the start method on the same thread twice. The correct answer will state that an exception is thrown at run-time. In reality, the JVM would probably ignore the second attempt to start the thread and would probably not throw the exception if the thread were already dead. This code example includes a lot of thread synchronization code that ensures that the thread is not dead when the start method is invoked the second time. You can run this example yourself and get the correct result. On the real exam, the synchronization code will not be included.
As it said,
on the real exam, the synchronization code will not be included. So, the first thread will probably be already dead before starting the second one. Which one is correct choice? If add an option like this: "G: The result is undetemined." It's better one,right??
Thanks,
Roger