Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

materkey-threads #206

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Conversation

materkey
Copy link

No description provided.

private void loop() throws IOException {
int count = 0;
final int maxTries = 10;
int connect_timeout = 200;
Copy link
Collaborator

Choose a reason for hiding this comment

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

camelCase

break;
} catch (Exception e) {
if (++count == maxTries) {
log.error("Can't connect, exiting ");
Copy link
Collaborator

Choose a reason for hiding this comment

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

e потерялось

client.loop();
}

private void loop() throws IOException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

метод надо разбить на несколько

try {
nbytes = in.read(buffer);
} catch (SocketTimeoutException ste) {
TimeUnit.MILLISECONDS.sleep(500);
Copy link
Collaborator

Choose a reason for hiding this comment

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

в чем логика? клиент уже отвалился

TimeUnit.SECONDS.sleep(retry_timeout);
retry_timeout *= 2;
} catch (InterruptedException e1) {
e1.printStackTrace();
Copy link
Collaborator

Choose a reason for hiding this comment

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

а почему прерываем слип до ретрая а не попытки коннекта?

int maxPoolSize = 3;
final BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();

final ThreadPoolExecutor pool = new ThreadPoolExecutor(3, maxPoolSize, 0L,
Copy link
Collaborator

Choose a reason for hiding this comment

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

всегда ровно 3 треда?

}
log.info(String.format("Can't connect, try again in %d sec ", retry_timeout));
try {
TimeUnit.SECONDS.sleep(retry_timeout);
Copy link
Collaborator

Choose a reason for hiding this comment

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

разрешение маловато, в случае если мы хотим 1 ретрай достаточно быстро на случай рестарта сервера -- не сможем настроить

log.info(String.format("Can't connect, try again in %d sec ", retry_timeout));
try {
TimeUnit.SECONDS.sleep(retry_timeout);
retry_timeout *= 2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

опционально можно сделать массив с хардкодными значениями и ходить по индексу

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>RELEASE</version>
Copy link
Collaborator

Choose a reason for hiding this comment

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

лучше прибить конкретную версию

@@ -19,6 +20,7 @@
/**
*
*/
@Ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

лишний дифф лучше убрать

@darkwrat
Copy link
Collaborator

баллы поставил


public static void main(String[] args) {
int maxPoolSize = 3;
final BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

здесь размер очереди будет Integer.MAX_VALUE.
а что если попробовать реализовать свой блокирующий pool.submit() на этой очереди? будет более прямо

private int port;
private AtomicLong serverCounter = new AtomicLong(0);
private Protocol<Message> protocol;
private Future[] fut;
Copy link
Collaborator

Choose a reason for hiding this comment

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

кто выпиливает отсюда завершенные таски?

private int maxClientsNum;


private ConcurrentMap<Long, Worker> workerMap;
Copy link
Collaborator

Choose a reason for hiding this comment

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

может попытаться запихать тот future внутрь этой мапы?

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.

None yet

2 participants