网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

Try to explain Singleton to us? Is it thread safe? If no, how to make

it thread safe?


参考答案

更多 “ Try to explain Singleton to us? Is it thread safe? If no, how to makeit thread safe? ” 相关考题
考题 40_____.A.heavyB.easyC. hardD.safe

考题 GiventhatTriangleimplementsRunnable,and:Whichtwostatements,insertedindependentlyatbothlines35and41,tendtoallowboththreadstotemporarilypauseandallowtheotherthreadtoexecute?() A.Thread.wait();B.Thread.join();C.Thread.yield();D.Thread.sleep(1);E.Thread.notify();

考题 5.classOrder2implementsRunnable{6.publicvoidrun(){7.for(intx=0;x〈4;x++){8.try{Thread.sleep(100);}catch(Exceptione){}9.System.out.print(r);10.}}11.publicstaticvoidmain(String[]args){12.Threadt=newThread(newOrder2());13.t.start();14.for(intx=0;x〈4;x++){15.//insertcodehere16.System.out.print(m);17.}}}哪一个插入到第15行,最有可能产生输出rmrmrmrm?()A.Thread.sleep(1);B.Thread.sleep(100);C.Thread.sleep(1000);D.try{Thread.sleep(100);}catch(Exceptione){}

考题 publicclassTestSevenextendsThread{privatestaticintx;publicsynchronizedvoiddoThings(){intcurrent=x;current++;x=current;}publicvoidrun(){doThings();}}Whichistrue?() A.Compilationfails.B.Anexceptionisthrownatruntime.C.Synchronizingtherun()methodwouldmaketheclassthread-safe.D.Thedatainvariable“x”areprotectedfromconcurrentaccessproblems.E.DeclaringthedoThings()methodasstaticwouldmaketheclassthread-safe.F.WrappingthestatementswithindoThings()inasynchronized(newObject()){}blockwouldmaketheclassthread-safe.

考题 publicclassMyLogger{privateStringBuilderlogger=newStringBuuilder();publicvoidlog(Stringmessage,Stringuser){logger.append(message);logger.append(user);}}TheprogrammermustguaranteethatasingleMyLoggerobjectworksproperlyforamulti-threadedsystem.Howmustthiscodebechangedtobethread-safe?()A.synchronizethelogmethodB.replaceStringBuilderwithStringBufferC.Nochangeisnecessary,thecurrentMyLoggercodeisalreadythread-safe.D.replaceStringBuilderwithjustaStringobjectandusethestringconcatenation(+=)withinthelogmethod

考题 publicclassAextendsThread{A(){setDaemon(true);}publicvoidrun(){(newB()).start();try{Thread.sleep(60000);}catch(InterruptedExceptionx){}System.out.println(Adone”);}classBextendsThread{publicvoidrun(){try{Thread.sleep(60000);}catch(InterruptedExceptionx){}System.out.println(Bdone”);}}publicstaticvoidmain(String[]args){(newA()).start();}}Whatistheresult?()A.AdoneB.BdoneC.AdoneBdoneD.BdoneAdoneE.Thereisnoexceptionthattheapplicationwillprintanything.F.Theapplicationoutputs“Adone”and“Bdone”,innoguaranteedorder.

考题 下列程序通过设定线程优先级,抢占主线程的CPU,选择正确的语句填入横线处。 class T14 implements Runnable { private Boolean fStop - true; public void run() { while(fStop) { System.out.println(Thread.currentThread().getName() + "run"); try { Thread.sleep(l); } catch(Exception e) { e.printStackTrace(); } } } public void stopRun() { fStop = false; } } public class Testl4 { public static void main(String[] args) { T14 t14 = new T14(); Thread t1 = new Thread(ti4, "T14"); Thread t = Thread.currentThread()'; ______; Ti.start(); T14.stopRun(); System.out.println ( "stop "); } }A.setPriority(Thread. MIN_PRIORITY)B.t1 .setPriority(Thread. MIN_PRIORITY)C.t.setPfiofity(Thread. MIN_PRIORITY)D.t14.setPriority(Thread. MIN_PRIORITY)

考题 用Thread子类实现多线程的步骤顺序是( ) A、声明Thread类的子类,创建Thread子类的实例,让线程调用start()方法B、声明Thread类的子类,在子类中重新定义run()方法,创建Thread子类的实例C、创建Thread子类的实例,让线程调用start()方法D、声明Thread类的子类,在子类中重新定义run()方法,创建Thread子类的实例,让线程调用start()方法

考题 The gold should be taken away to a secure place.A:clean B:pretty C:distant D:safe

考题 18、写出反义词 safe