- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我实现了一个 netty 4 http 服务器。
public void start() {
System.out.println("In Start method");
try {
ServerBootstrap b = new ServerBootstrap();
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new HttpServerPipelineFactory())
.option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, WriteBufferWaterMark.DEFAULT)
.childOption(ChannelOption.AUTO_READ, false)
.childOption(ChannelOption.SO_KEEPALIVE, true);
ChannelFuture f = b.bind(listenerPort).sync();
System.out.println("server started listening on port " + listenerPort);
f.channel().closeFuture().sync();
} catch (Exception e) {
e.printStackTrace();
}
}
HTTP 管道工厂类是 -
public class HttpServerPipelineFactory extends ChannelInitializer<Channel> {
@Override
protected void initChannel(Channel ch) {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("codec", new HttpServerCodec());
pipeline.addLast("compress", new HttpContentCompressor());
pipeline.addLast("decompress", new HttpContentDecompressor());
pipeline.addLast("aggregator", new HttpObjectAggregator( 512 * 1024));
pipeline.addLast("chunked", new ChunkedWriteHandler());
pipeline.addLast("flow", new FlowControlHandler());
pipeline.addLast("keep-alive", new HttpServerKeepAliveHandler());
pipeline.addLast("request", new AdvancedHTTPHandler());
}
}
AdvancedHTTPHandler 是 -
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH;
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
import static io.netty.util.CharsetUtil.UTF_8;
public class AdvancedHTTPHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
private static Logger logger = LoggerFactory.getLogger(HTTPRequestHandler.class);
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) {
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.copiedBuffer("My Netty".getBytes()), false);
response.headers().add(request.headers());
response.headers().set(CONTENT_LENGTH, response.content().readableBytes());
ctx.channel().writeAndFlush(response);
}
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
super.channelActive(ctx);
ctx.read();
}
}
在 Main.java 中 -
public class Main {
public static void main(String[] args) {
ResourceLeakDetector.setLevel(PARANOID);
HttpServer server = new HttpServer(5020);
server.start();
}
}
正如您在主应用程序中看到的那样,我设置了 ResourceLeakDetector.setLevel(PARANOID);
但我在应用程序日志中没有看到任何资源泄漏检测日志。
我缺少什么。我该如何解决这个问题?
最佳答案
我在您的代码中没有看到任何泄漏,因此没有报告泄漏是有道理的。只需将 SimpleChannelInboundHandler
替换为 ChannelInboundHandlerAdaptor
或在 channelRead0(...)
方法中调用 request.retain()
即可您将看到一份报告。
关于java - ResourceLeakDetector.setLevel(PARANOID) 不生成资源泄漏日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61134849/
我试图了解 logger.setLevel 的影响和 handler.setLevel 的影响之间的区别,其中 logger 和处理程序创建如下: import logging def getLogg
我在我的项目中使用了 java.util.Logger 并且我使用了一个简单的 ConsoleHandler。默认情况下,日志记录级别为“信息”。我想将级别更改为“良好”。但是,我必须同时更改 Log
我花了一些时间浏览网站上的 Python 记录器问题,希望我的问题能在那里得到解决。我已经设置了一个带有两个流处理程序的记录器,它们具有不同的格式和日志记录级别,这是我的代码库中的一个功能片段: im
我正在尝试在我的应用程序中使用此代码: def logger(log_file='base.log', set_level='INFO', identity='base'): set_le
此代码中是否有任何内容可以解释为什么我的信息消息没有进入日志。格式正确的警告及以上警告将进入两个日志文件。 初始化记录器: logger = logging.getLogger() f = loggi
情况:我有这个 log4j 记录器: private static final Logger logger = Logger.getLogger(ThisClassName.class); 我正在尝试
看看这个链接:https://docs.python.org/3/library/logging.html#levels 他们谈论日志级别,其中 DEBUG 的数值为 10,INFO 的数值为 20.
我正在尝试缩放可绘制对象但失败了。然而,这不是本例的问题,它似乎与 setLevel() 方法有关。 我很难从它声明的文档中弄清楚它的作用以及我应该在什么时候使用它: Specify the leve
我有一个 python 程序,它利用多处理来提高效率,以及一个为每个进程创建记录器的函数。记录器函数如下所示: import logging import os def create_logger(a
Deflater.setLevel()对我来说没有预期的效果。 static void test1() throws Exception { byte[] output = new byte
以下代码是从文档中复制的。我应该能够看到所有的信息日志。但我没有。即使我将 setLevel 设置为 INFO,我也只能看到警告及以上。 为什么会这样? foo.py: import logging
在 logging howto documentation有这个例子: import logging # create logger logger = logging.getLogger('simpl
假设我有以下代码: import logging import logging.handlers a = logging.getLogger('myapp') h = logging.handlers
我实现了一个 netty 4 http 服务器。 public void start() { System.out.println("In Start method"); try {
fmtter = logging.Formatter('%(asctime)s,%(msecs)05.1f (%(funcName)s) %(message)s', '%H:%M:%S') rock_
我正在尝试将可绘制对象存储在静态 SoftReferenceMap 中,用于每行包含进度条的 ListView。每行都有不同的进度,但是当我通过 setProgress(int) 设置它时,所有行都会
我正在尝试过滤来自 UDP 的 Python 日志消息,但出于某种原因,在接收端设置日志级别似乎不会影响传入消息。 接收端代码如下: import cPickle import logging imp
setLevel(okhttp3.logging.HttpLoggingInterceptor.Level)' 已弃用 setLevel 应该替换什么?删除已弃用的问题 最佳答案 根据文档“移动到 v
我有如下设置日志记录: def setUp(): LOG_FORMAT = '%(asctime)s %(levelname)-8s %(name)s %(message)s' #LO
假设我有以下代码: import logging import logging.handlers a = logging.getLogger('myapp') h = logging.handlers
我是一名优秀的程序员,十分优秀!