The project must be done individually with no other source(s). No exceptions.
Read the Academic Integrity link one more time.
Through its implementation, this project will familiarize you with the creation and execution of threads, and with the use of the Thread’s class methods. In order to synchronize the threads you will have to use (when necessary), run( ), start( ), currentThread( ), getName( ), join( ), yield( ), sleep(time), isAlive( ), getPriority( ), setPriority( ), interrupt( ), isInterrupted( ), and maybe synchronized methods.
In synchronizing threads, DO NOT use any semaphores. DO NOT use wait( ), notify( ) or notifyAll();
Tourists go to Ellis Island to learn about the beginnings of America, and sometimes to try to find out about their ancestors who immigrated to this country.
Every half hour a documentary movie is presented. If the movie is in session, visitors busy wait in the lobby of the movie theatre. When the previous session ends (announced by a clock thread), visitors hurry up to enter the theater and take one of the available seats (simulate this by increasing the priority of the visitor; after a sleep of random time, set its priority to its default value; use getPriority() and setPriority() methods)
If there are no free seats, visitors leave the room, and will wait to see the next presentation (you can implement the mutual exclusion over the shared variable free seats by having it access through a synchronized method, or by declaring it as volatile. Make sure that if you use synchronized methods you never have a thread sleep inside of them). On their way out, they want to be polite at the door, so visitors yield to each other (use yield() twice). Once the movie starts, no visitor can enter and disturb it.
While the movie is on visitors sleep for a long time (the only way to get out of sleep will be by an interrupt).
Your display should clearly show who got in the theater, who left, and who was able to see the current presentation.
When the movie ends (announced by a clock), a speaker will wake up the visitors by sending an interrupt to each visitor in the theater (use the interrupt() method. To check that it works, have a message part of the catch block).
Next, as a reward, the speaker gives out sets of party_tickets for a future movie. The audience will gather into groups of party_tickets size (maybe you want to use a Boolean
array/vector) and busy wait to be called. The speaker will call each group at once and distribute the tickets. After that, the speaker will busy wait for the end of the next movie.
Next the visitors will browse around for a while and eventually leave the theater. They leave in the order of their ID (let’s say in the theater you have T3, T5, T2 and T1. The order in which they leave is T1, T2, T3, T5. Use the isAlive() and join() methods.
In order to keep track of the time, we need an additional thread, named clock. The clock will signal the start time of the next movie and the end time of the previous movie, (between sessions the clock will sleep for a fixed time).
Throughout the day, they are four movie presentations. The speaker will terminate after the visitors of the last presentation leave the theater. The visitors terminate after they leave the theater or if they didn’t have the chance to see a presentation, when the museum closes.
Shortly after the four presentations end, the clock announces the closing of the museum, and terminates.
Initial values: numVisitors = 23
theaterCapacity = 5
The numVisitors should be an argument to the program.
Using the synchronization tools and techniques learned in class, synchronize the visitor threads, speaker and clock threads – in the context of the problem described above.
In order to simulate different actions you must pick reasonable intervals of random time. Make sure that the execution of the entire program is somewhere between 40 seconds and 90 seconds.
The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.
Get Free Quote!
250 Experts Online