public class JudgeUnixServer {
private static final String socketFile = ResourceConfig.getConfigString("judge.socket.fileName");
private ServerBootstrap serverBootstrap;
private EpollEventLoopGroup boss;
private EpollEventLoopGroup worker;
public void init() {
this.boss = new EpollEventLoopGroup();
this.worker = new EpollEventLoopGroup();
this.serverBootstrap = new ServerBootstrap();
JudgeUnixDomainChannelInit channelInit = new JudgeUnixDomainChannelInit();
this.serverBootstrap.group(this.boss,this.worker)
.channel(EpollServerDomainSocketChannel.class)
.option(UnixChannelOption.SO_BACKLOG,128)
// .childOption(UnixChannelOption.SO_REUSEADDR,true)
.childHandler(channelInit);
}
public void start() {
init();
// log.info("..........判题机Unix套接域正在启动.........");
try {
ChannelFuture channelFuture = this.serverBootstrap.bind(new DomainSocketAddress(socketFile)).sync();
channelFuture.channel().closeFuture().sync();
} catch (InterruptedException e) {
log.error(e.getLocalizedMessage(),e);
}
this.boss.shutdownGracefully();
this.worker.shutdownGracefully();
}
}
接下来是Spring Boot的全局启动
@SpringBootApplication
public class JudgmentApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(JudgmentApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
new Thread(() -> {
JudgeUnixServer server= new JudgeUnixServer();
server.start();
}).start();
}
}
我在编译成Jar包部署成功的时候,有时候重启的时候会全局阻塞。
然后定位到代码的问题,就是这行代码被阻塞了
我被这个问题困扰了两天,我迫切需要一个解决方案