Given:
and the code fragment:The threads t1 and t2 execute asynchronously and possibly prints ABCA or AACB.
You have been asked to modify the code to make the threads execute synchronously and prints ABC.
Which modification meets the requirement?
Given:
and the code fragment:The threads t1 and t2 execute asynchronously and possibly prints ABCA or AACB.
You have been asked to modify the code to make the threads execute synchronously and prints ABC.
Which modification meets the requirement?
To ensure that the threads execute synchronously and print 'ABC', the run() method needs to be synchronized. This ensures that one thread completes its execution of the run() method before the other thread can execute it. Replacing line n2 with 'public synchronized void run () {' will achieve this.
C is correct, A does nothing...
I think C is answer.
C is answer.
The answer is letter C, answer A does not print anything on the screen and the run() method needs to be syncronized.
public void run() { while(count < src.length){ System.out.println(src[count++]); } }