`
guoyiqi
  • 浏览: 968052 次
社区版块
存档分类
最新评论

java线程学生进实训室

 
阅读更多

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技术完成聊天室系统,深入学习使用Java语言。  2、使用Java 的多线程机制,深入理解Java多线程技术的应用。  3、使用GUI,对JFrame的深入学习。 4、使用网络编程,掌握基于TCP协议的Socket...

    Java线程讲解Java线程讲解

    Java线程讲解Java线程讲解Java线程讲解Java线程讲解Java线程讲解Java线程讲解Java线程讲解Java线程讲解Java线程讲解Java线程讲解

    线程 JAVA java线程 java线程第3版 java线程第2版第3版合集

    电子书相关:包含4个有关JAVA线程的电子书(几乎涵盖全部有关线程的书籍) OReilly.Java.Threads.3rd.Edition.Sep.2004.eBook-DDU Java Thread Programming (Sams) java线程第二版中英文 java线程第二版中英文 ...

    Java线程详解大全

    Java线程Java线程Java线程Java线程Java线程Java线程Java线程Java线程Java线程Java线程Java线程Java线程Java线程Java线程Java线程

    java多线程编程总结

    Java线程:概念与原理 Java线程:创建与启动 Java线程:线程栈模型与线程的变量 Java线程:线程状态的转换 Java线程:线程的同步与锁 Java线程:线程的交互 Java线程:线程的调度-休眠 Java线程:线程的调度-优先级 ...

    Java线程Java线程Java线程Java线程

    Java线程Java线程Java线程Java线程Java线程Java线程

    Java多线程知识点总结

    该文档总结了Java多线程相关的知识点,分享给大家,简单易懂!

    Java程序设计基础实训

    Java是面向对象的、支持多线程的解释型网络编程语言。它是目前Internet最流行的编程语言之一,具有高度的安全性、可移植性和代码可重用性。

    Java实训报告.docx

    湖南科技大学潇湘学院计算机科学与工程系计算机科学与工程专业2019年JAVA实训实验报告,报告中一共写有9个实训内容,每个内容都在本人博客中有详细介绍以及代码。其中目录为 一、矩阵的运算 二、求不同图形的周长...

    java 线程java 线程

    java 线程java 线程java 线程java 线程java 线程java 线程java 线程java 线程java 线程

    Java多线程编程总结

    Java 线程系列博文总结word化,编目如下,欢迎互相学习交流: Java线程:概念与原理 Java线程:创建与启动 Java线程:线程栈模型与线程的变量 Java线程:线程状态的转换 Java线程:线程的同步与锁 Java线程:...

    Java线程模块Java线程之秒表

    Java线程模块Java线程之秒表新手学习Java线程模块时,利用Java中设置线程的暂停间隔,做的简易秒表

    java线程同步java线程同步

    java线程同步java线程同步java线程同步

    java实训设计报告

    关键词:多线程,substance,对象序列化技术,卡片式布局,系统托盘,单例模式,sql语言,面向对象,正则表达式 小组成员分工 江海波:服务器界面设计,文档完善; 郑福德:聊天窗口toolbar里面的内容(包括字体,...

    java多线程笔记

    Java线程:概念与原理 2 一、操作系统中线程和进程的概念 2 二、Java中的线程 3 三、Java中关于线程的名词解释 3 四、线程的状态转换和生命周期 4 Java线程:创建与启动 7 Java线程:线程名称的设定及获取 10 Java...

    java 线程 dump 分析工具 2.3.3

    java 线程Dump 分析工具: Java的TDA线程转储分析器是一个用于分析Sun Java VM生成的线程转储和堆信息的小型Swing GUI(目前用1.4测试)。它从提供的日志文件中解析线程转储和类直方图。它提供关于发现的线程转储的...

    java线程 线程学习资料 java线程教程

    java线程 线程 教程 java线程教程 java线程学习资料 本教程有什么内容? 本教程研究了线程的基础知识— 线程是什么、线程为什么有用以及怎么开始编写使用线程的简单 程序。 我们还将研究更复杂的、使用线程的应用...

    经典之Java实训教材

    内容涉及:Java开发环境,Java中的类和对象,基本控制组件,用户自定义界面成分,容器、布局设计,包、接口和事件,异常用语异常处理,流式输入输出和文件操作,多线程程序设计。每章都有1~2个完整的就应用实例,...

    java线程.pdf

    java线程.pdf java 学习java

    Java的线程和Java AppletJava的线程和Java AppletJava的线程和Java Applet

    Java的线程和Java AppletJava的线程和Java AppletJava的线程和Java AppletJava的线程和Java AppletJava的线程和Java Applet

Global site tag (gtag.js) - Google Analytics