The project is separated in five packages:
-
domain: related to the business rules
- BankerObj.java
Contains the quantity and arrays of processes and available resources, in addiction to the AllocationA, ClaimC and NeedCA (C-A) matrices. The matrices are made with the List of ProcessObj with which we can dinamically add and remove processes. - ProcessObj.java
Used as a process object, it contains an ID and an array of resources, this array is the maximum of resources necessary for the process.
- BankerObj.java
-
port: the ports related to the application
- Cli.java
Handle the man-machine-interface to the application - FileDataInput.java
Handle the file data input
- Cli.java
-
thread: contains the threads
- ThreadNewProcess.java
Insert new processes to the application in runtime execution (6 process with 15 sec interval) - ThreadRunBanker.java
Run the banker algorithm itself. The simulation of a process execution is handled by the Thread.Sleep in 10 sec.
- ThreadNewProcess.java
-
usecase: usecases of the application
- AddProcess.java
Add the process in runtime, invoked by ThreadNewProcess each 15 sec. - CheckSafeState.java
Check if the system is in SAFE/ UNSAFE state - ExecuteBanker.java
Run the banker algorithm itself - LoadProcesses.java
Load the processes to the system from startFile.txt
- AddProcess.java
-
Main.java
Run the application starting all classes used by application
Input: ______________________________________________________________________________
Output:
The starterFile generate the following matrix:
The banker started in SAFE state
As the new processes are add the banker keep running, but updating the sequence of processes
The list of executed process:
Case 2, on this case the system is started in SAFE state but turn to UNSAFE when adding process at runtime:
Input:
Output:
The starterFile generate the following matrix:
The banker started in SAFE state
After insert P6 the system go to UNSAFE state
After that the system can't exit of the UNSAFE:
Conclusion
The algorithm works as expected managing a lot of Deadlocks. But handle new process insertion is a problem, the process
already enter allocating some resource, and, with that, the system go to UNSAFE state, in addiction to, the simulation
is not considering the execution time of a process, if a process takes a long time all other process need to wait until
the end.
Another not considered question is if a process need more resources when it is running, in this case all system will
stop. Despite that the banker's algorithm is interesting when it is running on a limited and controlled
operational system, with the knowledge of all processes used by the system.