Skip to content

KulR threads#159

Open
KulR wants to merge 14 commits intotehnotrack:masterfrom
KulR:KulR-threads
Open

KulR threads#159
KulR wants to merge 14 commits intotehnotrack:masterfrom
KulR:KulR-threads

Conversation

@KulR
Copy link
Copy Markdown

@KulR KulR commented May 23, 2018

No description provided.

Scanner scanner = new Scanner(System.in);
public void loop(){
try {
Socket socket = new Socket(host, port);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

В случае ошибок не закрываете соединение

socket.close();
break;
}
Message msg = new Message(1, line);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Почему timestamp = 1?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

1 - это тип сообщения(для последующего разграничения), в данный момент есть два типа сообщения: служебный и сообщение для всех пользователей, 1 и 2 соответственно.

import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.*;

import one.nio.mem.SharedMemoryBlobMap;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Импорты лишние точно. Такое у вас не используется

AdminThread admin = new AdminThread();
admin.start();
try {
while (true) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

А как остановить сервер корректно?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

через команду shutdown из потока admin(команда добавлена)

}

static class WorkThread extends Thread {
Socket socket;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Стоит указывать уровень доступа, например private

private int port;
static int freeThreads = 5;

synchronized static long setSynchonizedvalue(long value, int setvalue) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Плохой паттерн, изменяемое из разных мест глобальное состояние (переменая freeThreads)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

В данной версии нет поддержки ограниченного количества потоков(она планировалось либо с глобальной переменной либо с ThreadPool)

Socket socket;
long id;
String name;
String ShortName;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

переменная с маленькой букв

@Override
public void run() {
try {
out.writeObject(new Message(1, "connected"));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

таймштамп должен быть текущим времнем

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

1 - тип сообщения(выше написано подробнее)

if (msg.GetTs() == 1) {
String line = msg.getData();
line = ShortName + ">\t" + line;
msg.PutData(line);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

методы с маленькой буквы

static Logger log = LoggerFactory.getLogger(Server.class);

private int port;
static int freeThreads = 5;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Вашу проблему решил бы ThreadPool

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