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 !!!!!!!!!!!!!!!!!!!

最新文章

  1. 异步编程系列第01章 Async异步编程简介
  2. C#中DataTable转化为List<T>解析
  3. jQuery弹出关闭遮罩层
  4. [转]jsp与servlet的区别联系
  5. angular 兼容ie7 实现
  6. 网络模拟器WANem使用配置图文教程
  7. EF Attach时已存在的处理方式
  8. 转:Emmet:快速编写HTML,CSS代码的有力工具
  9. java中遍历List中的map问题
  10. Oracle 数据库用户管理
  11. 如何使用cygwin去编译cocos2dx项目中的C++文件
  12. 1630/2023: [Usaco2005 Nov]Ant Counting 数蚂蚁
  13. Nginx设置Https反向代理,指向Docker Gitlab11.3.9 Https服务
  14. linux 安装配置 sublime 进行 python 开发
  15. bash 特殊变量
  16. Lodop打印如何隐藏table某一列
  17. sencha touch 目录结构
  18. Quality of Service 0, 1 & 2
  19. http://202.194.116.8/webapps/portal/frameset.jsp?tab_id=_2_1&url=%2fwebapps%2fblackboard%2fexecute%2
  20. VCAP5-DCA Objective 1.3 – Configure and Manage Complex Multipathing and PSA Plug-ins

热门文章

  1. SINGLETON(单例模式)---(孤独的人)
  2. hibernate.cfg.xml文件的配置模板和不同数据库的配置參数
  3. Label的各个属性
  4. linux内核编译环境配置
  5. 模仿《百度音乐HD》添加到下载框动画
  6. oc深坑測试题及其答案
  7. GIT的下载、安装、与使用
  8. DL动态载入框架技术文档
  9. HBase经常使用操作之namespace
  10. poj3311(状压dp)