不会做作业,帮帮忙 有2个线程:student和teacher,student准备睡10分钟后再开始上课,teacher在输出3句“上课”后,吵醒student。请问应该如何编啊这个程序?麻烦高手帮帮忙 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class ThreadTest{ public static void main(String args[]) { Object obj=new Object(); StudentThead stu=new StudentThead(obj); stu.start(); TeacherThread teacher=new TeacherThread(obj); teacher.start(); }}class StudentThead extends Thread{ Object obj=null; StudentThead(Object obj) { this.obj=obj; } public void run() { synchronized(obj){ System.out.println("开始睡觉!"); try{ obj.wait(10*60*1000); } catch(Exception es) { } System.out.println("学生上课"); } } }class TeacherThread extends Thread{ Object obj=null; TeacherThread(Object obj) { this.obj=obj; } public void run() { synchronized(obj){ for(int i=0;i<3;i++) { System.out.println("上课了"); } obj.notify(); } } } public class ThreadTest { public static void main(String args[]) { Object obj=new Object(); StudentThead stu=new StudentThead(obj); stu.start(); TeacherThread teacher=new TeacherThread(obj); teacher.start(); } } class StudentThead extends Thread { Object obj=null; StudentThead(Object obj) { this.obj=obj; } public void run() { synchronized(obj){ System.out.println("开始睡觉!"); try{ obj.wait(10*60*1000); } catch(Exception es) { } System.out.println("学生上课"); } } } class TeacherThread extends Thread { Object obj=null; TeacherThread(Object obj) { this.obj=obj; } public void run() { synchronized(obj){ for(int i=0;i <3;i++) { System.out.println("上课了"); } obj.notify(); } } }从新发一次 class Student extends Thread{ public void run(){ try{ System.out.println("先睡10分钟"); sleep(600000); }catch(InterruptedException ie){ System.out.println("醒了"); } }}class Teacher extends Thread{ Student s=new Student(); public void run(){ for(int i=0;i<3;i++){ System.out.println("上课"); } s.interrupt(); }}public class TestTwo{ public static void main(String args[]){ Student student=new Student(); student.start(); Teacher teacher=new Teacher(); teacher.start(); }}如果我这样写为什么不行呢? 我希望编写一个下载www.tianya.cn论坛煮酒论史所有的网页 java 三维数组的理解(小弟不才) count+=count++;一个巨菜问题希望大家帮我解决下下? acm java输入两个数,中间用空格格开,如何再把它门分别取出来 新手,求教readLine()简单的小问题 一个我从没有看到的问题,麻烦大家来看下撒 在jbuilder x中,怎么查代码行数 java 多线程设计 谁能推荐本学java的书 常量存储在哪里? 关于类之间访问变量 JTable 背景色 为透明
{
public static void main(String args[])
{
Object obj=new Object();
StudentThead stu=new StudentThead(obj);
stu.start();
TeacherThread teacher=new TeacherThread(obj);
teacher.start();
}
}
class StudentThead extends Thread
{
Object obj=null;
StudentThead(Object obj)
{
this.obj=obj;
}
public void run()
{
synchronized(obj){ System.out.println("开始睡觉!");
try{
obj.wait(10*60*1000);
}
catch(Exception es)
{
}
System.out.println("学生上课");
}
}
}
class TeacherThread extends Thread
{
Object obj=null;
TeacherThread(Object obj)
{
this.obj=obj;
}
public void run()
{
synchronized(obj){
for(int i=0;i<3;i++)
{
System.out.println("上课了");
}
obj.notify();
}
}
}
public class ThreadTest
{
public static void main(String args[])
{
Object obj=new Object();
StudentThead stu=new StudentThead(obj);
stu.start();
TeacherThread teacher=new TeacherThread(obj);
teacher.start();
}
}
class StudentThead extends Thread
{
Object obj=null;
StudentThead(Object obj)
{
this.obj=obj;
}
public void run()
{ synchronized(obj){ System.out.println("开始睡觉!");
try{
obj.wait(10*60*1000);
}
catch(Exception es)
{
}
System.out.println("学生上课");
}
}
}
class TeacherThread extends Thread
{
Object obj=null;
TeacherThread(Object obj)
{
this.obj=obj;
}
public void run()
{
synchronized(obj){
for(int i=0;i <3;i++)
{
System.out.println("上课了");
}
obj.notify();
}
}
}从新发一次
public void run(){
try{
System.out.println("先睡10分钟");
sleep(600000);
}catch(InterruptedException ie){
System.out.println("醒了");
}
}
}class Teacher extends Thread{
Student s=new Student();
public void run(){
for(int i=0;i<3;i++){
System.out.println("上课");
}
s.interrupt();
}
}public class TestTwo{
public static void main(String args[]){
Student student=new Student();
student.start();
Teacher teacher=new Teacher();
teacher.start();
}
}
如果我这样写为什么不行呢?