|
|
@@ -15,6 +15,9 @@ import io.netty.util.internal.logging.InternalLogger;
|
|
|
import io.netty.util.internal.logging.InternalLoggerFactory;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* 正向代理(代理客户端)
|
|
|
@@ -32,10 +35,11 @@ public class ForwardProxyServer {
|
|
|
*/
|
|
|
private static final String REMOTE_HOST = "127.0.0.1";
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
+ public static void main(String[] args) throws InterruptedException {
|
|
|
List<MediaServerDTO> serverList = MediaServerDTO.getMediaServerList();
|
|
|
+ ExecutorService executorService = Executors.newFixedThreadPool(serverList.size());
|
|
|
for (MediaServerDTO server : serverList) {
|
|
|
- new Thread(() -> {
|
|
|
+ executorService.submit(() -> {
|
|
|
int proxyPort = server.getProxyPort();
|
|
|
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
|
|
|
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
|
|
@@ -54,14 +58,15 @@ public class ForwardProxyServer {
|
|
|
})
|
|
|
.childOption(ChannelOption.AUTO_READ, false)
|
|
|
.bind(proxyPort).sync().channel().closeFuture().sync();
|
|
|
- log.info("启动服务端口" + proxyPort + "成功");
|
|
|
} catch (Exception e) {
|
|
|
- log.error("启动服务端口" + proxyPort + "出错", e);
|
|
|
+ throw new RuntimeException(e);
|
|
|
} finally {
|
|
|
bossGroup.shutdownGracefully();
|
|
|
workerGroup.shutdownGracefully();
|
|
|
}
|
|
|
- }).start();
|
|
|
+ });
|
|
|
}
|
|
|
+ executorService.shutdown();
|
|
|
+ executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
|
|
|
}
|
|
|
}
|