题目
A.stop
B.synchronized
C.yield
D.notify
第1题
A.当线程执行结束就处于死亡状态
B.为线程分配资源就能从死亡状态转到可运行状态
C.应用程序停止运行,线程处于死亡状态
D.若要确认一个线程是否已经结束,可以调用Thread类的isAlive()方法
第3题
注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。
程序运行结果如下:
public class ex35_2
{
public static void main(String args[ ])
{
Runnable b1=new B("First");
Runnable b2=new B("Second");
Runnable b3=new B("Third");
Thread t1=new Thread(b1);
Thread t2=new Thread(b2);
Thread t3=new Thread(b3);
t1.start ();
t2.start ();
t3.start();
}
}
class B _____________________ Runnable
{
String s;
public B(String str)
{
s=str;
}
_________________
{
for(int i=1;i<3;i++)
{
System. out. println (s+ "运行!");
try
{
Thread.sleep((int) (Math.random() *100) );
}
catch (InterruptedException e)
{
e.printStackTrace ();
}
}
System. out.println (s+"结束!");
}
}
第4题
A.currentThread()方法返回当前正在运行的线程对象
B.线程A通过调用start()方法使其进入可运行状态
C.若线程A调用isAlive()方法并返回true,说明A正在运行中
D.在线程A中执行线程B的join()方法,则线程A等待直到B执行完成
第5题
A.在线程A中执行线程B的join()方法,则线程A等待直到B执行完成
B.线程A通过调用start()方法使其进入可运行状态
C.若线程A调用isAlive()方法并返回true,说明A正在运行中
D.currentThread()方法返回当前正在运行的线程对象
第10题
阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。
【说明】
下面的Java程序演示了如何使用Applet在网页上显示图形用户界面CUI(graphical user interface),该实例显示一个时钟。每当浏览器显现Applet的内容时都调用start()函数,让applet得以开始工作(尤其时那些被stop()函数所关闭的工作)。每当浏览器不再显现Applet的内容时都调用stop()函数,让applet得以关闭某些甚耗资源的工作调用destroy()函数之后也会调用此函数。每当浏览器将Applet从网页移除时都调用destroy()函数,已执行"applet不再被使用时"应该做的最后释放资源等动作。每当调用repaint()函数时,或网页窗口须重新刷新时调用paint()函数。
【Java程序】
import java.applet.*;
import java.awt.*;
public class ClockApplet extends (1) implements Runnable
{ //运行函数,每隔一秒刷新一次时间
public void run(){
while (true){
try{
Thread.sleep(1000);
}
catch (InterruptedException e){}
(2); //刷新当前时间
}
}
public void start(){ //调用此函数,并根据条件启动时钟线程或重起线程
if(clockThread= =null){
clockThread = new Thread(this);
clockThread. start();//启动新创建的线程
}
else
clockThread.(3);//恢复挂起的线程
}
public void stop(){ //挂起时钟线程
if (clockThread ! = null)
clockThread. (4);
}
public void destroy(){//停止时钟线程
if (5) {
clockThread.stop();
clockThread = null;
}
}
public void paint(Graphics g){//在网页上重新显示时间
g. drawString(new java.util. Date().toString(), 10,30);
}
private Thread clockThread;
}
第11题
A.关闭正在编辑的文档,但是Word窗口仍然存在
B.Word停止运行,窗口关闭
C.Word窗口最大化,继续运行
D.Word窗口最小化,但并未结束运行
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!