EXERCISE OF THREAD (2)

xiaoxiao2021-03-06  71

11.Which Three Are WAIT (); d. Synchronized (); d. Synchronized (); d. Synchronized (); d. Synchronized (); d. Synchronized (); e. Interrupt (); f. Wait (); Long msecs; g. Sleep (long msecs); h. yield (); (abf). Java doc12.given the folload.1.public class waittest {2. public static void main (string [] args) {3. System.out.Print ("1"); 4. synchroized (args) {5. System.out.print ("2"); 6. Try {7. Args.wait (); 8.} 9. Catch InterruptedException E) {} 10.} 11. System.out.print ("3"); 12.} 13.} What is the result of triseing of compile and run this program? A. It fails to Compile Because The IllegalMonitorStateException of PRY Wait () is not dealt with in line 7.b. 1 2 3c. 1 3d. 1 2E. at runtime, it throws an illegalmonitorstateexception when Trying to wait.f. It will do be synchronized on the This Object. (d) will print 1 and 2, but because there is no other thread to advertise the main thread, they will not return to adjust With Wait, 3 will not be printed, the program will freeze in Chapter 7; A is wrong, because IllegalMonitorStateException is an unspected exception, so it won't make a clear process; f is wrong because any Object You can use Synchroized, in addition, when running a static method, it does not belong to this object; 13.ssume the Following Method Is Properly Synchronized and Called from A Thread A on an Object B: Wait (2000); After Calling this Method, When Will THEAD A BECOME A Candidate TO GET Another Turn At The CPU? A. After Thread a is notified, or after two seconds.

B. after the lock on b is released, or after two seconds.

C. Two Seconds After Thread a is notified.

D. Two Seconds After Lock B Is Released. (A). A is correct, any one of the two events will become a thread waiting. B is wrong, because a thread waiting in a waiting, unless a Notification occurs, otherwise it will not return Runnable when the lock is released. C is wrong, because threads will turn directly into a thread waiting in a waiting thread. 14.Which Two Are True? A.THE NOTIFYALL () Method Must Be Called from a synchronized context.b.to call wait () , An Object Must OWN The Lock on The Thread.

C.THE NOTIFY () Method is defined in class java.lang.thread.

D.When A Thread Is Waiting As a Result of Wait (), IT Release ITS Locks.e.The Notify () Method Causes A Thread To Immediately Release ITS LOCKS.

F.The difference between notify () and notifyAll () is that notiffyAll () notifies all waiting threads, regardless of the object they're waiting on. (AD). Java doc15.Assume you create a program and one of your threads ( called backgroundThread) does some lengthy numerical processing. What would be the proper way of setting its priority to try to get the rest of the system to be very responsive while the thread is running? (Choose all that apply.) A.backgroundThread.setPriority (Thread.low_priority);

B.backgroundthread.SetPriority (thread.max_priority);

C. Backgroundthread.SetPriority (1);

D. backgroundthread.SetPriority (thread.no_priority); E.BackgroundthRead.SetPriority (thread.min_priority);

F.Backgroundthread.SetPriority (thread.norm_priority);

G.backgroundthread.SetPriority (10); (C.E). Set the thread priority, up to 10, default is 5. The three methods are: max_priority, min_priority, norm_priority. 16.Which Three Guarantee That A Thread Will Leave The Running State? A. Yield ()

B. Wait ()

C. Notify ()

D. NotifyAll ()

E. SLEEP (1000)

F. AliveThread.join ()

转载请注明原文地址:https://www.9cbs.com/read-110501.html

New Post(0)