We can control a threads schedule by using a rich set of Java methods, such as s
ID: 3841951 • Letter: W
Question
We can control a threads schedule by using a rich set of Java methods, such as sleep(), yleld().join().setPriority(). Walt(), notify() and notify AlI(). True False The following block of code creates a copyOrwriteArrayList. adds elements to it, and prints the contents: copy OnWriteArrayList cowList = new CopyOnWriteArrayList (); cowList. add(4); cowList. add(2); Iterator it = cowList. it = cowList. iterator(); cowlist. add(6); while(it. hasNext()) {System. out. print(it. next() + " ");} What is the result? Compilation fails 4 2 6 6 12 An exception is thrown at runtime 4 2Explanation / Answer
Answer to 76:
TRUE. Yes we can control the execution of threads by using the available rich sets of JAVA functions. Every function that is used for the thread execution has a totally different functionality that not only affects that particular thread but also the other threads in execution.
sleep() makes the current thread to sleep for the specified milliseconds.
yield() makes the current executing thread to pause and allows the next threads to execute.
join() makes one thread to wait for the completion of another thread.
setpriority() function is used to change the priority of threads according to which the execution would be decided.
wait() function allows the current thread to wait till it is either invoked using notify() or notifyall().
Answer to 77:
The answer is 4 2 6 as we are just adding on the integer numbers to the list and using iterator priting out its value.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.