lab-02 pull request Belous Artem#38
Conversation
| public void updateTunnel () { | ||
| if (tunnel.isFull()){ | ||
| while (ships.size() > tunnel.getMaxShips()) { | ||
| ships.remove(ships.size() - 1); | ||
| } | ||
| } else { | ||
| if (ships.size() <= tunnel.getMaxShips()){ | ||
| tunnel.setShipsInTunnel(ships.size()); | ||
| } else { | ||
| tunnel.setShipsInTunnel(tunnel.getMaxShips()); | ||
| while (ships.size() > tunnel.getMaxShips()) { | ||
| ships.remove(ships.size() - 1); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } |
There was a problem hiding this comment.
Какое0то странное взаимодействие. Кажется массив кораблей должен лежать в тунеле и все, а не в генераторе и потом как-то с этим взаиомдействовать.
| public void updateTunnel () { | ||
| if (tunnel.isFull()){ | ||
| while (ships.size() > tunnel.getMaxShips()) { | ||
| ships.remove(ships.size() - 1); |
There was a problem hiding this comment.
Добавление и удаление не синхронизированны.
There was a problem hiding this comment.
Функция updateTunnel всегда используется в блоке synchronized(ships)
| ship_capacity_min = jsonObject.get("ship_capacity_min").getAsInt(); | ||
| ship_capacity_max = jsonObject.get("ship_capacity_max").getAsInt(); | ||
|
|
||
| String[] cargoTypes = new Gson().fromJson(jsonObject.get("cargo_types"), String[].class); |
| while (necessaryIngredients.get(index) > 0 && currentStock.get(index) > 0){ | ||
| int itemsLeft = currentStock.decrementAndGet(index); |
There was a problem hiding this comment.
Между этими двумя стрчоками может произойти событие и тогда currentStock.get(index) == 0 и после этого уйдет в минус.
|
|
||
| int itemsToPut = Math.min(ship.getCargoLeft(), this.unloadingSpeed); | ||
| this.stock.set(index, Math.min(this.dockCapacity, | ||
| this.stock.get(index) + itemsToPut)); |
There was a problem hiding this comment.
тут гонка с действиями в hobos.
There was a problem hiding this comment.
Не совсем понимаю, при каких условиях тут может возникнуть проблема
| if (itemsLeft < 0){ | ||
| currentStock.incrementAndGet(index); | ||
| break; | ||
| } |
There was a problem hiding this comment.
Это не совсем поможет исправить ситуацию, надо делать через CAS.
|
|
||
| private void readFromJsonFile() { | ||
| try { | ||
| String filePath = "src\\by\\BelArtem\\docks_and_hobos\\config.json"; |
There was a problem hiding this comment.
Путь до этого файла передается аргументов в вашу программу.
|
Основная оценка:
В итоге: |
No description provided.