Skip to content

Commit

Permalink
执行器线程数量配置
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghanzheng committed Jul 11, 2023
1 parent a689eed commit c48db42
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ public class RetryRunnable implements Runnable {

@Override
public void run() {
int times = getTimes();
String currentTimes = current + "/" + times;
concept.getLogger().info("Start retry and current is " + currentTimes);
retryable.accept(e -> {
int times = getTimes();
String retryErrorMessage = "Retry failed " + currentTimes;
int newCurrent = current + 1;
int period = getPeriod(newCurrent);
String retryErrorMessage = "Retry failed " + current + "/" + times;
MessageRetryException retryException =
new MessageRetryException(retryErrorMessage, e, error);
if (current < times) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,11 @@ public MessageIdempotentVerifierFactory nettyMessageIdempotentVerifierFactory()
}

@Bean
public ScheduledExecutorFactory nettyScheduledExecutorFactory() {
return new ScheduledExecutorFactoryImpl()
.addScopes(NettyScoped.NAME);
public ScheduledExecutorFactory nettyScheduledExecutorFactory(NettyLoadBalanceProperties properties) {
ScheduledExecutorFactoryImpl factory = new ScheduledExecutorFactoryImpl();
factory.setSize(properties.getExecutor().getSize());
factory.addScopes(NettyScoped.NAME);
return factory;
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class NettyLoadBalanceProperties {
*/
private LoadBalanceProperties loadBalance = new LoadBalanceProperties();

private ExecutorProperties executor = new ExecutorProperties();

@Data
public static class ServerProperties {

Expand Down Expand Up @@ -67,6 +69,12 @@ public enum Subscriber {
}
}

@Data
public static class ExecutorProperties {

private int size = 1;
}

@Data
public static class MessageProperties {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
@Inherited
@EnableConnectionLoadBalanceConfiguration
@EnableConfigurationProperties(WebSocketLoadBalanceProperties.class)
@Import({WebSocketLoadBalanceConfiguration.class,
WebSocketLoadBalanceImportSelector.class})
@Import({WebSocketLoadBalanceImportSelector.class, WebSocketLoadBalanceConfiguration.class})
public @interface EnableWebSocketLoadBalanceConcept {
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,12 @@ public MessageIdempotentVerifierFactory wsMessageIdempotentVerifierFactory() {
}

@Bean
public ScheduledExecutorFactory wsScheduledExecutorFactory() {
return new ScheduledExecutorFactoryImpl()
.addScopes(WebSocketScoped.NAME);
public ScheduledExecutorFactory wsScheduledExecutorFactory(WebSocketLoadBalanceProperties properties) {
ScheduledExecutorFactoryImpl factory = new ScheduledExecutorFactoryImpl();
factory.setSize(properties.getExecutor().getSize());
factory.addScopes(WebSocketScoped.NAME);
return factory;

}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class WebSocketLoadBalanceProperties {
*/
private LoadBalanceProperties loadBalance = new LoadBalanceProperties();

private ExecutorProperties executor = new ExecutorProperties();

@Data
public static class ServerProperties {

Expand Down Expand Up @@ -166,6 +168,12 @@ public static class MonitorProperties {
}
}

@Data
public static class ExecutorProperties {

private int size = 1;
}

@Data
public static class MessageProperties {

Expand Down

0 comments on commit c48db42

Please sign in to comment.