Skip to content

Conversation

@nrsxx
Copy link
Owner

@nrsxx nrsxx commented Apr 22, 2017

No description provided.

Copy link

@DanAnastasyev DanAnastasyev left a comment

Choose a reason for hiding this comment

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

У тебя куча бинарных файлов в репозиторий попало. Почисть их и настрой gitignore

@@ -0,0 +1,4 @@
public interface CustomQueue<E> {

Choose a reason for hiding this comment

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

А зачем ты этот интерфейс создал, если потом не используешь никак?

import java.util.LinkedList;
import java.util.Queue;

public class MyQueue<T> implements CustomQueue<T> {

Choose a reason for hiding this comment

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

MyQueue, конечно, очень говорящее название...

import java.util.LinkedList;
import java.util.Queue;

public class MyQueue<T> implements CustomQueue<T> {

Choose a reason for hiding this comment

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

Вообще говоря, в java уже есть класс очереди, который умеет блокировать поток при отсутствии элементов

@Override
public synchronized void enqueue(T task) {
queue.add(task);
// Wake up anyone waiting on the queue to put some item.
Copy link

@DanAnastasyev DanAnastasyev Apr 22, 2017

Choose a reason for hiding this comment

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

Ну зачем же так палиться...

Copy link

Choose a reason for hiding this comment

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

Неловко получилось, мда.
Давайте попробуем вычислить новизну кода. По моим подсчётам она (без учёта теста) составляет 11 строк (возможно, меньше). Остальные изменения являются добавленными пустыми строчками, переименованными переменными, либо переписанными комментариями.
Хватает ли 11 строк кода на то, чтобы зачесть задачу? Определённо, нет.

А за повторную попытку списывания я бы предложил запретить сдавать эту задачу. Что, кстати, довольно грустно с учётом того, что её решение является необходимым условием получения зачёта.


private final int threadPoolCapacity;
private MyQueue<Callable> myQueue = new MyQueue();
private ArrayList<Thread> threads = new ArrayList();
Copy link

@DanAnastasyev DanAnastasyev Apr 22, 2017

Choose a reason for hiding this comment

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

Старайся использовать интерфейсы, а не реализации:

private CustomQueue<Callable> myQueue = new MyQueue<>();
private List<Thread> threads = new ArrayList<>();

Тогда бы появился глубинный смысл у создания интерфейса очереди

private ArrayList<Thread> threads = new ArrayList();

private ThreadPool(int capacity) {
this.threadPoolCapacity = capacity;

Choose a reason for hiding this comment

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

Зачем this?

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

public class Task implements Callable {

Choose a reason for hiding this comment

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

Кстати, в задании было про Runnable и реализацию определенного интерфейса

for (int i = 0; i < threadPoolCapacity; ++i) {
threads.get(i).interrupt();
}
System.out.println("Good bye!");

Choose a reason for hiding this comment

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

Не надо в System.out в таком классе писать. Мало ли как он использоваться будет

System.out.println("Начало задачи");
TimeUnit.SECONDS.sleep(time);
System.out.println("Конец задачи");
return null;

Choose a reason for hiding this comment

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

Зачем?

}

@Override
public Object call() throws InterruptedException {

Choose a reason for hiding this comment

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

Правильнее было бы не throws InterruptedException, а обернуть sleep в try-catch

@Override
public synchronized void enqueue(T task) {
queue.add(task);
// Wake up anyone waiting on the queue to put some item.

Choose a reason for hiding this comment

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

Хороший же коммент был, зачем стирать

int num = Integer.parseInt(i.toString());//args[0]);
int i = 3;
int num = i;//args[0];
ThreadPool threadPool = new ThreadPool(num);

Choose a reason for hiding this comment

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

Будь смелее, пиши сразу ThreadPool threadPool = new ThreadPool(3);!

myQueue.enqueue(r);
}

public static void main(String... args) throws InterruptedException, ExecutionException {

Choose a reason for hiding this comment

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

Вообще говоря, обычно все пишут public static void main(String[] args). Не очень понимаю, откуда ты String... выкопал

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.

4 participants