EXERCISE OF THREAD (3)

xiaoxiao2021-03-06  66

20.Given the following.public class syntinner {public static void main (string [] args) {thread t = new three () {f = new foo (); {F.Increase (20);}}; t. start ();?..}} and assuming that data must be protected from corruption, what - if anything - can you add to the preceding code to ensure the integrity of data A Synchronize the run method.B Warp a synchronize (this) Around the call to f.increase (). c. The existing code will not compile.d. The existing code will............................ Synchronize the increase () method. (F) .21.given the following.1. Public class test {2. Public static void main (string [] args) {3. Final foo f = new foo (); 4. Thread T = New Thread (New Runnable ()) {5. public void Run () {6. f.dostuff (); 7.} 8. }; 9. Thread g = new thread () {10. Public void run () {11. F.dostuff (); 12.} 13.}; 14. T.Start (); 15. G.start () ; 16.} 17.} 1. Class foo {2. INT x = 5; 3. Public void dostuff () {4. IF (x <10) {5. // Nothing to do6. Try {7. Wait ( ); 8.} Catch (interruptedException ex) {} else () {10. System.out.println ("x is" x ); 11. If (x> = 10) {12. Notify () 14.} 14.} 14.} 16.} What is the result?

A.THE CODE WILL NOT Compile Because of An Error On Line 12 of Class Foo.b.The Code Will Not Compile Because of An Error On Line 7 of Class Foo.c.The Code Will Not Compile Because of An Error Online 12 Of class test.d.the code will not compile because of some.an Exception Occurs at runtime.fx is 5 x IS 6 (e). Because threads do not belong to objects when calling Wait () Lock, if the method is synchronized, the code will have an exception at runtime. Public static void main (string [] args) {new thread () {public void run () {system.out.println ("run");}} .start ();

This code does not produce Compile Error !!

Public class a {private interface {void show ();

} / * Class Cla Implements INA {Void Show () {// Some Great Code Here}} * /} Interface INA If you don't want to give other Class Implement, you are here Mark Private.

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

New Post(0)