通过什么方法可以将线程A的优先级设置为MAX_PRIORITY( )。
A:getPriority( ) B:getPriority()和setPriority( ) C:setPriority( ) D:线程优先级不可更改
下列方法可以通过Thread类就可以调用,而不需要通过Thread类的实例进行调用的是 ( )
A:sleep() B:start() C:setPriority() D:suspend()
请在下面横线处填入适当的代码,将线程对象runner[2]的优先级设置为最高。
class ThreadTest extends Thread
public static void main(String args[])
ThreadTest[] runner = new ThreadTest[4];
for(int j = 0; j<4; j++) runner[j] = new ThreadTest( );
for(int j = 0; j<4; j++) runner[j].start( );
【7】
runner[3].setPriority(MIN_PRIORITY);
public void run)
for(int i = 0; i<100000; i++);
System.out.println(getName( ) + "线程的优先级是:"
+ getPriority( ) + "计算完毕");
nmner[2lsetPriority(MAX_PRIORITY);
下列程序通过设定线程优先级,抢占主线程的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)
下列程序的输出结果是______。 class T44 implements Runnable { public void run( ) { System.out.print in (Thread.currentThread ( ).getName ( ) + "运行" ); } } public class ex44 { public static void main(String[] args) { Thread t1 = new Thread(new T44( ), "t1"); Thread t2 = new Thread(new T44 ( ) , "t2"); t1.setPriority(Thread. MAX_PRIORITY); t2.setPriority(Thread.MIN_PRIORITY); t2. start ( ); t1.start ( ); } }
A:t1 运行 t2 运行 B:t2 运行 t1 运行 C:t1 运行 t1 运行 D:t2 运行 t2 运行
调用线程的下列方法中,( )可以改变该线程在生命周期中的状态。
A:setPriority ( ) B:currentThread ( ) C:start ( ) D:aetiveCount ( )
下列程序通过设定线程优先级,抢占主线程的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(Threa MIN_PRIORIT B:t1 .setPriority(Threa MIN_PRIORIT C:setPfiofity(Threa MIN_PRIORIT D:t14.setPriority(Threa MIN_PRIORIT
下列方法可以通过Thread类就可以调用,而不需要通过Thread类的实例进行调用的是 ( )
A:sleep() B:start() C:setPriority() D:suspend()