Conversation
|
|
||
| DateTimeFormatter mediumTimeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM); | ||
|
|
||
| Thread timePrinter = new Thread(printTimeCyclical(twoSeconds, mediumTimeFormatter), "timePrinter"); |
| public static Runnable printTimeCyclical(Duration duration, DateTimeFormatter formatter) { | ||
| return () -> { | ||
| while (!Thread.currentThread() | ||
| .isInterrupted()) { |
There was a problem hiding this comment.
в общем-то, логика понятна, но практически избыточна. Как правило, проверка на прерывание используется тогда, когда действительно есть шанс, что поток будет прерван
| while (!Thread.currentThread() | ||
| .isInterrupted()) { | ||
| System.out.println(LocalDateTime.now() | ||
| .format(formatter)); |
There was a problem hiding this comment.
подобные переносы выглядят не очень. Лучше уж в одну строку. Или выноси в переменную, если хочется перенести
| .interrupt(); | ||
| } | ||
| } | ||
| }; |
There was a problem hiding this comment.
как по мне - переусложнил, но в точки зрения попрактиковаться с новым API - норм
| public static <T> void print2DArray(int[][] array) { | ||
| for (int[] row : array) { | ||
| for (int column : row) { | ||
| System.out.printf("[%s]".formatted(column)); |
There was a problem hiding this comment.
если printf() - formatted() лишний
| tableFiller.join(); | ||
| } | ||
|
|
||
| private Runnable tableFillingProcess(int[][] table, IntSupplier value) throws InterruptedException { |
| } catch (InterruptedException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| }, "rowFiller"); |
There was a problem hiding this comment.
имена тредов обычно не задаются вручную - в этом мало смысла, пока нет тред пулов. С ними познакомишься позже (или уже познакомился)
| row[i] = value.getAsInt(); | ||
| } | ||
| }; | ||
| } |
There was a problem hiding this comment.
как будто можно было описать лаконичнее/декомпозировать иначе. И, опять же, переусложняешь
| try { | ||
| fillRow(row, partCount, value); | ||
| } catch (InterruptedException e) { | ||
| throw new RuntimeException(e); |
There was a problem hiding this comment.
Зачем? В каком случае может вывалиться интерраптед ниже по стеку?
There was a problem hiding this comment.
как будто join закомментил, а здесь не подчистил
| } | ||
| } | ||
| }; | ||
| } |
There was a problem hiding this comment.
В виде стрима получилось бы красивее:)
| private Runnable tableFillingProcess(int[][] table, IntSupplier value) { | ||
| return () -> { | ||
| for (int[] row : table) { | ||
| Arrays.setAll(row, x -> value.getAsInt()); |
There was a problem hiding this comment.
Даже не знал о таком методе:)
| public class FunctionExecutor<T, R> implements Callable<R> { | ||
| T value; | ||
| Function<T, R> function; | ||
| R result; |
There was a problem hiding this comment.
что с идентификаторами доступа?
|
|
||
| return result; | ||
| } | ||
| } |
There was a problem hiding this comment.
Намудрил. Зачем Callable в этом решении? Здесь он как будто из-за рекомендации в условии. Но именно в этой имплементации он оказался не нужен:)
Также, почему Function? Вполне возможна ситуация, когда входного параметра нет. Или их несколько. Как будто неудачный подбор функционального интерфейса
|
|
||
| thread.start(); | ||
|
|
||
| while (true) { |
There was a problem hiding this comment.
можно упростить, засунув условие if в условие цикла
No description provided.