Instructor: Dr. Simina Fluture
CSCI 34 CSCI 34 CSCI 34CSCI 34 0 Summer 201 ummer 201 ummer 201ummer 201ummer 201 4
Project 1 – Due Date: Friday, Aug. 1st
Through its implementation, this project will familiarize you with the creation and execution of threads, and the use of the Thread class methods. In order to synchronize the threads you will have to use the following methods when necessary: run( ), start( ), currentThread( ), getName( ), join( ), yield( ), sleep(time), isAlive( ), getPriority( ), setPriority( ), interrupt( ), and synchronized methods for mutual exclusion. You CANNOT use wait(), notify, or notifyAll( )
Note: the projects must be done individually. No exceptions.
Any collaboration will be treated as cheating.
Online Office Hours
Students come to school and wait (use busy waiting) in front of the computer lab until it is time for the lab to open. Once the lab is open, students enter the lab to the capacity of the lab. If the capacity is reached no additional students can enter the lab. Students beyond the lab capacity will terminate their execution.
There are two types of questions that the student might have. The type and number of questions that each student will be allowed to ask is determined randomly.
Type A: the student can email the teacher up to #questions_A. These questions do not need an immediate answer from the teacher.
Type B: the student will have a chat session with the teacher. During a chat session, the student is allowed to ask at most #questions_B.
Once the student enters the lab, he will take some time to think about his questionA. (use yield( ) and later on sleep(random time)). Each question should contain a timestamp (use age()) and the name of the student (use getName()).
Type A questions: As soon as the student determines his questionA, he will be in a rush to send it to the teacher. (implement this by having the student increase his priority, use getPriority(), and setPriority(). Simulate sending the question by sleep(random time) and immediately after that reset the thread’s priority to the default value). All of the questions sent by students will be answered by the teacher in the order in which they have been sent.
Instructor: Dr. Simina Fluture
After the student is done sending his typeA questions, if he wants to have a chat with the teacher, he needs to wait until the chat session starts and it is his turn to chat. Once it is his turn to chat, he will send a question to the teacher and wait for an answer. If he has fewer than #questions_B he needs to let the teacher know when it is his very last question (when his chat session ends).
After his chatting session, the student will browse the Internet waiting for the online office hour to end (use sleep(time), where time is long enough such that when the online office hours end, the student will be awakened by an interrupt())
Next the students will leave the lab in ascending order of their name. (Implement this using isAlive() and join()). For example if there are 4 student threads named from T0 to T3. T3 will join 2T, T2 will join T1, T1 will join T0 and T0 after some sleep of random time will terminate.
The teacher arrives at his office before the online office hour begins. He spends some time answering typeA questions, but might not be able to answer all of them. Once the time for the online chatting session arrives, he will inform the first student waiting to chat that he is online and can take questions. He chats with students in the order in which they queue for the online chat session.
Once the office hour ends, the teacher will terminate as well. The timer will keep track of the times and, if necessary, signal the correct threads.
Note: set realistic times for the office hour and chatting sessions. For example, the teacher should be able to answer at least 10 typeB questions.
Synchronize the student threads, teacher thread and timer thread following the conditions of the story. Instead of creating a timer thread, you can chose to have the main thread taking track of the specific times. It is your choice.
For example a possible time scale can be (you might consider additional time intervals):
Teacher’s arrival time
Start of online office hour
start online chatting session
end online chatting session
end online office hour
Instructor: Dr. Simina Fluture
Use appropriate System.out.println() statements in the program. Also make use of the age() method provided to keep track of the Threads age and action time.
There are no real messages exchanged; it is just a simulation.
capacity, #Students, #questions_A, and #questions_B should be read as command line arguments.
Don’t hardcode. The program should work under any values for these variables.
Defaults values: capacity 10
#Students 15
#questions_A 4
#questions_B 2
The submission requirements will be posted shortly in a separate file.
Good Luck !!!!!!!!!!!!!!!!!!!

java线程学生进实训室的更多相关文章

  1. 《JAVA课程设计》实训第四天——《猜猜看》游戏

    第四天,本来想进一步去改进<猜猜看>游戏的.可是非常多问题都不理解.也不熟悉怎么去弄到连接数据库.统计猜对次数,所以并没有进行再多的改动. 基本上就是这种执行结果了 import java ...

  2. JAVA第三次实训作业

    ---恢复内容开始--- 1. 编写“学生”类及其测试类. “学生”类: 类名:Student 属性:姓名.性别.年龄.学号.5门课程的成绩 方法1:在控制台输出各个属性的值. 方法2:计算平均成绩 ...

  3. Java第四次实训作业

    1.编写“电费管理类”及其测试类. 第一步 编写“电费管理”类1)私有属性:上月电表读数.本月电表读数2)构造方法:无参.2个参数3)成员方法:getXXX()方法.setXXX()方法4)成员方法 ...

  4. Java第一阶段项目实训

    时间:2016-3-27 17:09 银行综合业务平台业务需求 1.首页  ---------------银行综合业务平台------------------- 1开户     2登录    3.退出 ...

  5. Java第4次实训作业

    编写"电费管理类"及其测试类. 第一步 编写"电费管理"类 私有属性:上月电表读数.本月电表读数 构造方法:无参.2个参数 成员方法:getXXX()方法.se ...

  6. Java企业实训 - 01 - Java前奏

    前言: 虽然个人专攻.NET方向,不过由于个人是干教育行业的,方方面面的东西,不能说都必须精通,但肯定多少都会涉及到. 一个菜鸟学员,从啥都不会,经过一步步学习,最后到企业上手掌管一个模块甚至一个项目 ...

  7. 《JAVA程序设计》实训第一天——《猜猜看》游戏

    课程实训是做一个猜猜看的小游戏.对于对代码不熟悉不了解的我来说的确挺难的.可是我还是会努力的. import java.awt.EventQueue; import javax.swing.JFram ...

  8. 学校实训作业:Java爬虫(WebMagic框架)的简单操作

    项目名称:java爬虫 项目技术选型:Java.Maven.Mysql.WebMagic.Jsp.Servlet 项目实施方式:以认知java爬虫框架WebMagic开发为主,用所学java知识完成指 ...

  9. Java实训:实训一 ——长春职业技术学院 16级网络工程

    Java实训:实训一 本文会解释一些设计思路. 想看具体过程,请转:https://www.cnblogs.com/lxwlxw/p/10114187.html 笑维的码云项目命名不太对,所以我来:h ...

随机推荐

  1. 为cocos2dx添加ndk库

    碰到很多坑: 1:引用库定义成include $(BUILD_SHARED_LIBRARY),结果生成了两个so文件,应该把库声明为BUILD_STATIC_LIBRARY 2:把库的java放到了项 ...

  2. Java反射机制的使用方法

    Java的反射机制同意你在程序执行的过程中获取类定义的细节.有时候在程序执行的时候才得知要调用哪个方法,这时候反射机制就派上用场了. 获取类 类的获取方法有下面几种: forName().通过Clas ...

  3. POJ 3835 &amp; HDU 3268 Columbus’s bargain(最短路 Spfa)

    题目链接: POJ:http://poj.org/problem?id=3835 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=3268 Problem ...

  4. ESP8266学习笔记1:怎样在安信可全功能測试板上实现ESP-01的编译下载和调试

    近期调试用到了安信可的ESP-01模块,最终打通了编译下载调试的整个通道,有一些细节须要记录,方便兴许的开发工作. 转载请注明:http://blog.csdn.net/sadshen/article ...

  5. 进一步解 apt-get 的几个命令

    用 apt-get 也非常久了,没多想它的实现,近期遇到 gstreamer 装不上的问题.才多看看了它 apt-get 就是从网上下载包,并安装到本地 手工下载 dpkg 包,而后 "dp ...

  6. ps中图层混合模式、多图层叠加、不透明度、填充、图层样式详解

    图像领域中,通过进行一下想法的时候,都要通过用ps看下是不是合理,而ps中图层是必用的一个功能,下面详解一下图层有关的叠加原理. 基本顺序是图层从下往上继续, 先计算图层的填充,再计算样式.最后计算不 ...

  7. 小猪的Android入门之路 day 1

    小猪的Android入门之路 Day 1 Android相关背景与开发环境的搭建 ------转载请注明出处:coder-pig 本节引言: 随着社会经济的发展,移动互联网的越来越热,手机APP开发显 ...

  8. poj 3270 更换使用

    1.确定初始和目标状态. 明确.目标状态的排序状态. 2.得出置换群,.比如,数字是8 4 5 3 2 7,目标状态是2 3 4 5 7 8.能写为两个循环:(8 2 7)(4 3 5). 3.观察当 ...

  9. Twitter僵尸帐号厂商雇佣中国员工专填验证码_Web2.0 - Microblogging 微博_cnBeta.COM

    Twitter僵尸帐号厂商雇佣中国员工专填验证码_Web2.0 - Microblogging 微博_cnBeta.COM Twitter僵尸帐号厂商雇佣中国员工专填验证码

  10. Java 模拟队列(一般队列、双端队列、优先级队列)

    队列: 先进先出,处理类似排队的问题,先排的.先处理,后排的等前面的处理完了,再处理 对于插入和移除操作的时间复杂度都为O(1).从后面插入,从前面移除 双端队列: 即在队列两端都能够insert和r ...