First commit lab-02 Anton Drazdoŭski#37
Open
aadeglmmy wants to merge 2 commits into
Open
Conversation
Rrenkens
reviewed
Dec 26, 2023
Comment on lines
+20
to
+31
| int generatingTime = configReader.getGeneratingTime(); | ||
| int shipCapacityMin = configReader.getShipCapacityMin(); | ||
| int shipCapacityMax = configReader.getShipCapacityMax(); | ||
| String[] cargoTypes = configReader.getCargoTypes(); | ||
| int maxShips = configReader.getMaxShips(); | ||
| int dockQuantity = configReader.getDocks(); | ||
| int unloadingSpeed = configReader.getUnloadingSpeed(); | ||
| int[] dockCapacity = configReader.getDockCapacity(); | ||
| int hoboQuantity = configReader.getHobos(); | ||
| int[] ingredientsCount = configReader.getIngredientsCount(); | ||
| int stealingTime = configReader.getStealingTime(); | ||
| int eatingTime = configReader.getEatingTime(); |
Owner
There was a problem hiding this comment.
Кмк ConfigReader уже заточен под структуру, поэтому мог уже возвращать и Tunnel, Docks и т. д.
| } | ||
|
|
||
| private Ship generateShip() { | ||
| Random random = new Random(); |
Owner
There was a problem hiding this comment.
Лучше не создавать на каждый вызов метода generateShip новый инстанс.
| while (ship.getCapacity() > 0) { | ||
| dockLock.lock(); | ||
| try { | ||
| while (dockFullness[cargoTypeIndex] >= capacity) { |
Owner
There was a problem hiding this comment.
Может быть такое, что нагенериили x одинаковых короблей, и тогда с этой точки не сдвинутся будет.
| } | ||
| } | ||
| try { | ||
| Thread.sleep(unloadingSpeed * 1000L); |
Owner
There was a problem hiding this comment.
unloadingSpeed – это сколько за секунду товаров разгружает док.
| } | ||
| } | ||
| try { | ||
| Thread.sleep(unloadingSpeed * 1000L); |
Owner
There was a problem hiding this comment.
Спать с взятым мьютексом не очень хорошая идея.
Comment on lines
+52
to
+86
| do { | ||
| while (true) { | ||
| synchronized (hobos) { | ||
| while (hobos.getStolenIngredients()[cargoTypeCounter] | ||
| == hobos.getIngredientsCount()[cargoTypeCounter]) { | ||
| cargoTypeCounter = (cargoTypeCounter + 1) % numOfCargoTypes; | ||
| if (cargoTypeCounter == cargoTypeIndex) { | ||
| breaker = true; | ||
| break; | ||
| } | ||
| } | ||
| if (breaker) { | ||
| breaker = false; | ||
| break; | ||
| } | ||
| synchronized (docks[dockCounter]) { | ||
| if (!(docks[dockCounter].getDockFullness()[cargoTypeCounter] != 0 | ||
| && hobos.getStolenIngredients()[cargoTypeCounter] | ||
| < hobos.getIngredientsCount()[cargoTypeCounter])) { | ||
| break; | ||
| } | ||
| docks[dockCounter].decrementDockFullness(cargoTypeCounter); | ||
| hobos.incrementStolenIngredients(cargoTypeCounter); | ||
| } | ||
| } | ||
| try { | ||
| Thread.sleep(stealingTime * 1000L); | ||
| } catch (InterruptedException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| // System.out.println("Hobo " + this + " stole from dock " + docks[dockCounter] + " cargo " | ||
| // + cargoTypeCounter); | ||
| } | ||
| dockCounter = (dockCounter + 1) % docks.length; | ||
| } while (dockCounter != dockIndex); |
Owner
There was a problem hiding this comment.
Не очень понял смысл этого цикла.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.