简体   繁体   English

Java多线程飞行控制程序的结构

[英]Structure of a Multithreaded Flight Control Program in Java

I have to write a program in Java that takes flight data from a CSV file and simulates the flight; 我必须用Java编写一个程序,该程序从CSV文件中获取飞行数据并模拟飞行。 that is, use a thread to change the state of each flight. 也就是说,使用线程更改每个排期的状态。 Here's a more specific description from the project page: 这是项目页面上的更具体的描述:

Write a program that manages information flow regarding flight status across many airlines and airports. 编写一个程序来管理有关许多航空公司和机场之间航班状态的信息流。 The airline monitor, the event generator and the airport status monitors will be initialized with the daily flight schedule using provided CSV file. 航空公司监控器,事件生成器和机场状态监控器将使用提供的CSV文件以每日航班时间表进行初始化。 The schedule covers flights that depart during the busiest hour of the day 4-5pm. 该时间表涵盖了在每天下午4点至下午5点最繁忙的时间出发的航班。

Now, here's a description of all the threads I have to implement: 现在,这是我必须实现的所有线程的描述:

Airline Monitor threads: starts a thread for each airline to receive and publish changes to the threads represented by the departure and arrival cities involved. 航空公司监控程序线程:为每个航空公司启动一个线程,以接收并发布对所涉及出发和到达城市代表的线程的更改。 For example, if flight 244 from BHM to DCA is delayed, publish the delay to the BHM and DCA flight status monitors. 例如,如果从BHM到DCA的航班244延误,则将延迟发布到BHM和DCA航班状态监视器。

Airport Flight Status Monitor threads: starts a thread for each airport and monitors all flights at that airport. 机场航班状态监视器线程:启动每个机场的线程并监视该机场的所有航班。 Each airport receives events on flights from each airline as they are generated. 每个机场在生成航班事件时都会接收来自每个航空公司的航班事件。 Each thread will publish the current flight status for the airport to an arrival and departure file. 每个线程都会将机场的当前航班状态发布到到达和起飞文件中。

Flight Event Generator thread: starts a single thread to generate changes to flights, including delays, boarding, left gate, take off, landed, and at gate. Flight Event Generator线程:启动一个线程以生成航班变更,包括延误,登机,左闸,起飞,着陆和登机口。

My question is simple in nature. 我的问题本质上很简单。 I'm struggling to find a good starting point and structure for the program. 我正在努力寻找程序的良好起点和结构。 Should it just be one main file with threads weaving throughout? 它应该只是一个贯穿整个线程编织的主文件吗? Or should I implement an object-oriented structure, with classes for each type of thread? 还是应该使用每种线程的类来实现面向对象的结构?

Finally, obviously this is a convoluted instance of the producer-consumer problem. 最后,显然这是生产者-消费者问题的一个复杂例子。 I've chosen to use a circular buffer to store the flight information that needs to be passed between threads. 我选择使用循环缓冲区来存储需要在线程之间传递的航班信息。 Would it be possible to give an example of how a circular buffer is implemented for this type of problem (but not this problem specifically)? 是否可以举一个例子说明如何为这种类型的问题实现循环缓冲区(但不是专门针对此问题)? Thanks! 谢谢!

EDIT: I don't have to design the whole airport system; 编辑:我不必设计整个机场系统; this is specifically a multithreading project. 这是一个专门的多线程项目。 Consider the following line from the CSV file: 考虑CSV文件中的以下行:

1,sw,mdw,mco,1600,:50

This specifies that this is the first flight of the day, on Southwest Airlines, from Chicago Midway to Orlando, taking off at 1600 hours (4:00 PM), with a flight time of 50 minutes. 这表明这是西南航空今天从芝加哥中途机场飞往奥兰多的第一班航班,起飞时间为1600小时(4:00 PM),飞行时间为50分钟。 I don't need classes Airport and Flight; 我不需要机场和航班课程。 these are simulated by these data from the CSV. 这些是由CSV中的这些数据模拟的。 I'm just not sure what to do with the 'southwest' airline thread, the 'mdw' and 'mco' airport threads, and the flight event generator thread, and how they should interact. 我只是不确定该如何处理“西南”航空公司线程,“ mdw”和“ mco”机场线程以及飞行事件生成器线程,以及它们应该如何交互。

Take a look at the docs. 看一下文档。 You'll find all the API components related to concurrence there: http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/package-summary.html 您将在此处找到与并发相关的所有API组件: http : //docs.oracle.com/javase/7/docs/api/java/util/concurrent/package-summary.html

For reading the file, I'd suggest using channels: http://docs.oracle.com/javase/7/docs/api/index.html?java/util/concurrent/package-summary.html 为了阅读文件,我建议使用以下渠道: http : //docs.oracle.com/javase/7/docs/api/index.html?java/util/concurrent/package-summary.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM