Skip to content

Лабораторная 1 Хогоев#11

Open
Artikhog wants to merge 5 commits intomasterfrom
master
Open

Лабораторная 1 Хогоев#11
Artikhog wants to merge 5 commits intomasterfrom
master

Conversation

@Artikhog
Copy link

No description provided.

}
// можно запустить executor на виртуальных потоках
// this.executor = Executors.newVirtualThreadPerTaskExecutor();
this.executor = Executors.newFixedThreadPool(numProgrammers + numWaiters);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вопрос заранее на защиту: расскажите офлайн потом, почему вы выбрали такой экзекутор. Есть же куча других. Будет здорово, если подкрепите замерами

public Waiter(int id, Kitchen kitchen) {
this.id = id;
this.kitchen = kitchen;
this.programmerQueue = new LinkedBlockingQueue<>();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему вы выбрали эту стркутуру? Как у вас обеспечивается равномерность накормленности?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Заменил на PriorityBlockingQueue

secondSpoon.acquire();
try {
System.out.println("Programmer " + id + " is eating (" + (mealsEaten.get() + 1) + " meal)");
mealsEaten.incrementAndGet();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если я правильно понял, то они у вас едят мгновенно. Попробуйте добавть слип на случайное время, или каждый программист ест за свое какое то время константное, не важно, главное чтобы не у всех было одинаковое

synchronized (this) {
while (!permissionToEat.get() && running && waiter.isKitchenOpen()) {
wait(200);
if (!permissionToEat.get() && waiter.isKitchenOpen()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как будто лишний кусок кода -- как будто достаточно просто положить в очередь. Либо расскажите, зачем такая эвристика


public class Main {

public static void main(String[] args) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Понимаю, что вы потестили через мейн. Но чисто по условиям таски -- сделайте пж несколько тестов. Можно в качестве ассертов проверять равномерность накормленности. А так достаточно тестов на успешное выполнение для нескольких конфигураций

}

private void think() throws InterruptedException {
System.out.println("Programmer " + id + " is thinking");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как будто они у вас думают мгновенно. См. коммент про время приема пищи

add sleep on eat and thinking
remove unnecessary reordering by programmer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants