创建一个线程并让它处于可运行状态的语句是_ Thread A=new Thread(); A.start
第1题:
语句Thread thread1=new SomeThreadClass()成功运行后,线程thread1处于生命周期的______状态。
第2题:
A.通过Thread类的构造方法创建线程
B.Thread类提供了start()方法创建线程
C.通过实现Runnable接口创建线程
D.通过使用Thread类提供的interrupt()方法创建线程
第3题:
通过实现Runnable接口创建线程,请在下面横线处填入代码完成此程序。
注意:不改动程序结构,不得增行或删行。
class ThreadTest implements Runnable
{
Thread thrObj;
public static void main(String args[])
{
System.out.println("这是一个通过实现接口创建线程的例子");
ThreadTest testObj=new ThreadTest();
testObj.create();
}
public void create()
{
if(thrObj= =null)
{
thrObj=new Thread(this,"myThread");
______
}
}
public void run()
{
System.out.println("Thread"+throbj.getName()+":"+"在运行!");
}
}
第4题:
Thread类中启动线程体的方法是( )。
A.start()
B.resume()
C.init()
D.run()
第5题:
如果使用Thread t=new Test()语句创建一个线程,则下列叙述正确的是
A.Test类一定要实现Runnable接口
B.Test类一定是Thread类的子类
C.Test类一定是Runnable的子类
D.Test类一定是继承Thread类并且实现Runnable接口
第6题:
当使用SomeThread t=new SomeThread( )创建-个线程时,下列叙述中正确的是( )。
A.Some Thread类是包含run( )方法的任意Java类
B.Some Thread类-定要实现Runnable接口
C.Some Thread类是Thread类的子类
D.Some Thread类是Thread类的子类并且要实现Run-nable接口
第7题:
下列哪个方法用来定义线程的具体行为,也就是定义线程体?
A.start( )
B.run( )
C.init( )
D.thread( )
第8题:
下列程序通过实现Runnable接口创建一个线程,选择正确的语句填入程序的横线处。 class MyRun implements Runnable { String str; MyRun(String s) { str = s; } public void run() System.out.println(str); } } public class ex40 { public static void main(String[] args) { String name = "实现阶段Runnable 接口"; MyRun my = new MyRun(name); Thread th = th. start ( ); } }
A.new MyRun(my)
B.new Thread()
C.new Thread(my)
D.Thread(my)
第9题:
在创建Thread对象之后,调用线程的( )方法开始执行线程。
A.start()
B.interrupt()
C.run()
D.stop()
第10题:
从实现了Runnable接口的对象创建线程对象的方法是,建立一个单独的Thread对象,并把可运行对象传递给专门的Thread类的()方法。
第11题:
第12题:
第13题:
请阅读下面程序 public class ThreadTest{ public static void main(String args[]) ( Thread t1=new Thread(new Hello()); Thread t2=new Thread(new Hello()); t1.start(); t2.start(); } } class Hello implements Runnable { int i; public void run() { while(true) { System.out.prinfin("Hello"+i++); if(i=5) break; } } } 该程序创建线程使用的方法是
A.继承Thread类
B.实现Runnable接口
C.t1.start()
D.t2.start()
第14题:
对于下面语句的说法,不正确的是( )。Thread thrObj=new Thread( );
A.系统没有为该线程对象分配资源
B.只能启动或者终止
C.创建了-个空的线程对象
D.可以调用其他方法
第15题:
对于下面语句的说法,不正确的是 Thread thrObj=new Thread();
A.系统没有为该线程对象分配资源
B.只能启动或者终止
C.创建了一个空的线程对象
D.可以调用其他方法
第16题:
下列程序的运行结果是______。 class A implements Runnable { int a; iht i = 2; A(int x) { a = x; } public void run() { while(i > 0) { System.out.println("线程" + a); i--; } } } public class Testl3 { public static void main(String[] args) { Thread a1 = new Thread(new A(1)); Thread a2 = new Thread(new A(2)); a1.start(); a2.start(); } }
A.线程1 线程1 线程2 线程2
B.线程1 线程2
C.线程1 线程2 线程1 线程2
D.线程1 线程1 线程1 线程1
第17题:
在程序中,DataPool是一个数据池,能存放一个血型数据,线程a和线程b负责向其中存放数据,一次只能有一个线程向其中存放数据,数据放入DataPool以后,该线程随机休眠一段时间,让另外一个线程运行,请将程序补充完整。
注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。
class PutData extends Thread
{
DataPool s;
int c;
String name;
public PutData(DataPool s,String name)
{
this.s=s;
this.name=name;
}
public void run()
{
for(int i=0;i<10000000;i++)
{
c=(int)(Math.random()*10);
s.setData(c);
System.out.println(name+":push"+c);
try
{
______((int) (Math.random()*1000));//休眠
}
catch(InterruptedException e)
{}
}
}
}
class DataPool
{
private int data=0;
public ______void setData(int d)
{
data=d;
}
}
public class simple
{
public static void main(String[] args)
{
DataPool s=new DataPool();
PutData a=new PutData(s,"Thread a");
PutData b=new PutData(s,"Thread b");
a.start();
b.start();
}
}
第18题:
下列程序创建了一个线程并运行,横线处应填入的正确代码是( )。 public class Try extends Thread{ public static void main(String args[]){ Thread t=new Try; ; } public void runf System.out.println(”Try!"); } }
A.t.start
B.t.class
C.t.thread
D.t.static
第19题:
对于下面语句,不正确的说法是______。 Thread thrObj=new Thread( );
A.系统没有为此线程对象分配资源
B.只能启动或者终止
C.创建了一个空的线程对象
D.可以调用其他方法
第20题:
A、声明Thread类的子类,创建Thread子类的实例,让线程调用start()方法
B、声明Thread类的子类,在子类中重新定义run()方法,创建Thread子类的实例
C、创建Thread子类的实例,让线程调用start()方法
D、声明Thread类的子类,在子类中重新定义run()方法,创建Thread子类的实例,让线程调用start()方法
第21题:
下列说法中错误的一项是 ( )
A.使用继承Thread类创建线程,可以直接调用线程的方法
B.通过实现Runnable接口创建线程,体现了面向对象的思想
C.Thread类从面向对象的角度看,是虚拟CPU的封装
D.通过实现Runnable接口创建线程,会影响Thread类的体系
第22题:
关于线程的创建过程,下面四种说法正确的有哪些?()
第23题:
定义Thread类的子类,重写Thread类的run()方法,创建该子类的实例对象,调用对象的start()方法
定义Thread类的子类,重写Thread类的run()方法,创建该子类的实例对象,调用对象的run()方法
定义一个实现Runnable 接口的类并实现run()方法,创建该类实例对象,将其作为参数传递给Thread类的构造方法来创建Thread对象,调用Thread对象的start()方法
定义一个实现Runnable 接口的类并实现run()方法,创建该类对象,然后调用run()方法
第24题: