-
Notifications
You must be signed in to change notification settings - Fork 28
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
base: master
Are you sure you want to change the base?
materkey-threads #206
Conversation
private void loop() throws IOException { | ||
int count = 0; | ||
final int maxTries = 10; | ||
int connect_timeout = 200; |
There was a problem hiding this comment.
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 "); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) { | ||
int maxPoolSize = 3; | ||
final BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
может попытаться запихать тот future внутрь этой мапы?
No description provided.