@SpringBootApplication @RestController public class HighConcurrencyApplication { @GetMapping("/") public String helloWorld() { return "Hello, World!"; } public static void main(String[] args) { SpringApplication.run(HighConcurrencyApplication.class, args); } } public class HighConcurrencyServer { private int port; public HighConcurrencyServer(int port) { this.port = port; } public void run() throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(new HighConcurrencyServerHandler()); } }) .option(ChannelOption.SO_BACKLOG, 128) .childOption(ChannelOption.SO_KEEPALIVE, true); ChannelFuture f = b.bind(port).sync(); f.channel().closeFuture().sync(); } finally { workerGroup.shutdownGracefully(); bossGroup.shutdownGracefully(); } } public static void main(String[] args) throws Exception { int port = Integer.parseInt(args[0]); new HighConcurrencyServer(port).run(); } } public class HighConcurrencyActor extends AbstractActor { @Override public Receive createReceive() { return receiveBuilder() .match(String.class, msg -> { System.out.println("Received message: " + msg); getSender().tell("Processed message: " + msg, getSelf()); }) .build(); } public static void main(String[] args) { ActorSystem system = ActorSystem.create("HighConcurrencySystem"); ActorRef actorRef = system.actorOf(Props.create(HighConcurrencyActor.class), "highConcurrencyActor"); actorRef.tell("Hello, World!", null); } } - Spring Boot: https://spring.io/projects/spring-boot - Netty: https://netty.io/ - Akka: https://akka.io/


上一篇:
下一篇:
切换中文