| Author |
Threads Question
|
Piyush Jain
Ranch Hand
Joined: Apr 25, 2003
Posts: 60
|
|
I have confusion with this particular question on Marcus Green Exam. Which of the statements are true? Select two. 1. The idea of threading is same as multitasking 2. No two threads can access the same variables 3. using synchronization within a thread may cause performance penalties. 4. the use of threads may make the exact path of execution unpredictable. now the answer is 3 & 4. is 1 also not the right answer? Thanks
|
 |
Tom Tolman
Ranch Hand
Joined: Sep 02, 2004
Posts: 83
|
|
The definition of multitask is: The concurrent operation by one central processing unit of two or more processes. If you consider all threads to belong to the same process- it is not multitasking. However, I would normally consider different threads to be engaging in different processes. It is semantic: is a process an entire application, or a thread? From the answer given on the answer key, they are interpreting a process to be a separate application, and not different threads. I disagree with this answer and hope nothing like that (semantic interpretation of vague english words) are on the real test.
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12266
|
|
To me, multitasking implies processes working in separate memory spaces - ie separate programs. Java Threads all work in the same JVM memory space. Bill
|
Java Resources at www.wbrogden.com
|
 |
Doyle Matt
Ranch Hand
Joined: Jul 05, 2004
Posts: 76
|
|
4. the use of threads may make the exact path of execution unpredictable. threads can make the path of execution unpredictable? how come? an execution is a top-down approach, meaning from line 1 to line 2 to line 3 and so forth. it can be interrupted but execution goes to the next line. please help.
|
SCJP 1.4
|
 |
Peter den Haan
author
Ranch Hand
Joined: Apr 20, 2000
Posts: 3252
|
|
Doyle, I think the point is that execution may go from line 4 in thread A to line 10 in thread B. Within a single thread the path of execution is still predictable, but the order of execution across threads is unpredictable in the sense that you don't get any guarantees about it. This unpredictability does imply that if you don't carefully control the interaction between threads, the behaviour of your entire application becomes unpredictable. This, of course, is the whole issue of thread safety. - Peter
|
 |
Doyle Matt
Ranch Hand
Joined: Jul 05, 2004
Posts: 76
|
|
|
Thanks Peter. Now I can sleep tonight w/o thinking of why and how it is about threads. Many Thanks again.
|
 |
 |
|
|
subject: Threads Question
|
|
|