小编mab*_*abn的帖子

go:http服务器在osx上不起作用

示例性的HTTP服务器并不为我工作.源代码:

package main

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}

func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe("127.0.0.1:8080", nil)
}
Run Code Online (Sandbox Code Playgroud)

当我尝试连接所有我得到的是:

$ curl 127.0.0.1:8080
curl: (7) Failed to connect to 127.0.0.1 port 8080: Operation timed out
$ nc -v -G 5 127.0.0.1 8080
nc: connectx to 127.0.0.1 port 8080 (tcp) failed: Operation timed out
Run Code Online (Sandbox Code Playgroud)

虽然nc尝试连接tcpdump只显示SYN数据包:

$ tcpdump -i lo0 port 8080
tcpdump: verbose output suppressed, use -v or …
Run Code Online (Sandbox Code Playgroud)

sockets macos networking go httpserver

21
推荐指数
1
解决办法
3811
查看次数

为什么Go可以将GC暂停降低到1ms以下而JVM没有?

所以有:https://groups.google.com/forum/?fromgroups#!topic/golang-dev/Ab1sFeoZg_8:

今天我向垃圾收集器提交了更改,这些更改使得典型的最坏情况下的停止世界时间小于100微秒.这应该特别改善具有许多活动goroutine的应用程序的暂停,这可能会显着延长暂停时间.

如果JVM用户长时间挣扎,那么高GC暂停就是其中之一.

什么是(架构?)约束阻止JVM将GC暂停降低到Go级别,但是不影响Go?

garbage-collection jvm go

14
推荐指数
1
解决办法
1666
查看次数

kafka消费者0.9向后兼容吗?

即将到来的kafka消费者0.9.x是否会与0.8经纪商兼容?

换句话说 - 可以只切换到新的消费者实现,而不涉及其他任何事情?

apache-kafka kafka-consumer-api

8
推荐指数
2
解决办法
5709
查看次数

JSF通过EL和复合组件泄漏内存

注意:我使用的是mojarra 2.1.20和丰富的面孔4.2.2.

我已经分析了一个堆转储,我注意到EL表达式驻留在会话中的LRUMap中.有谁知道为什么以及如何避免它?

我遇到的问题与包含以下行的复合组件有关:

  <rich:select ... valueChangeListener="#{cc.listValuesChangeListener}"
Run Code Online (Sandbox Code Playgroud)

使用支持bean my.package.MultiComboSelection.显然my.package.MultiComboSelection有一个名为listValuesChangeListener的方法.

我看到的问题是LRUMap包含ContextualCompositeMethodExpression(上面的valueChangeListener表达式的表示),cc属性引用MultiComboSelection.MultiComboSelection扩展了UINamingContainer,因此具有父/子属性 - 引用了组件树.

结果是16MB的内存不能被垃圾收集,因为有一个参考链:

session-> LRUMap-> ContextualCompositeMethodExpression-> MultiComboSelection-> parent和16MB

问题是 - 为什么会发生这种情况以及如何解决或解决它?

Class Name                                                                                   | Shallow Heap | Retained Heap | Retained Heap
--------------------------------------------------------------------------------------------------------------------------------------------
my.package.MultiComboSelection @ 0x78dc2bd50                                                 |           96 |    16 466 272 |    16 466 272
|- component javax.faces.component.UIComponentBase$FacetsMap @ 0x78dbbbd58                   |           48 |           128 |              
|- parent javax.faces.component.UIPanel @ 0x78dbbbdd8                                        |           88 |           760 |              
|- cc com.sun.faces.facelets.el.ContextualCompositeMethodExpression @ 0x78dc2bce0            |           32 |    16 466 384 |              
|  |- …
Run Code Online (Sandbox Code Playgroud)

jsf memory-leaks el composite-component

7
推荐指数
1
解决办法
2274
查看次数

varargs和null参数

所以,我有一个奇怪的问题.此表达式:method.invoke(target, null)throws java.lang.IllegalArgumentException:参数数量错误

问题是这个表达式在hibernate内部很深(确切地说是BasicPropertyAccessor $ BasicGetter),我想它应该可以正常工作(直到最近才这样做)

我在eclipse中调试了这个问题,事实上,如果我(在显示视图中)调用method.invoke(target)method.invoke(target, (Object[]) null)一切正常.我确信我的班级有这个吸气剂,它没有任何争论.所以...问题是,到底发生了什么?!

编辑:

  • method是java.lang.reflect.Method的一个实例,并指向所述getter
  • target是具有公共X getX()getter的类的实例
  • JDK 1.6.0_31
  • hibernate中的代码(BasicPropertyAccessor:143):

    public Object get(Object target) throws HibernateException {
        try {
            return method.invoke(target, null);
        }
        catch{ ... }
    }
    
    Run Code Online (Sandbox Code Playgroud)

java reflection hibernate variadic-functions

6
推荐指数
1
解决办法
7207
查看次数

使用动态值覆盖Junit Test中的默认Spring-Boot application.properties设置

我想覆盖测试中application.properties中定义的属性,但@TestPropertySource只允许提供预定义的值.

我需要的是在随机端口N上启动服务器,然后将此端口传递给spring-boot应用程序.端口必须是短暂的,以允许同时在同一主机上运行多个测试.

我不是指嵌入式http服务器(jetty),而是在测试开始时启动的一些不同的服务器(例如zookeeper)和被测试的应用程序必须连接到它.

实现这一目标的最佳方法是什么?

(这里是一个类似的问题,但答案没有提到临时端口的解决方案 - 在Junit Test中覆盖默认的Spring-Boot application.properties设置)

java junit spring automated-tests spring-boot

6
推荐指数
3
解决办法
1580
查看次数

为什么 DefaultMessageListenerContainer 强烈推荐使用 sessionTransacted

DefaultMessageListenerContainer 的Javadoc说

强烈建议将“sessionTransacted”设置为“true”或指定外部“transactionManager”。

为什么强烈推荐?这个神秘建议的背后是什么?

java spring activemq-classic jms spring-jms

4
推荐指数
1
解决办法
4156
查看次数

gc.log是异步编写吗?安全地将gc.log放在NFS挂载上?

我多次听到将gc.log放在NFS卷上的想法很糟糕,因为这可能会导致gc暂停时间更长。当前的jdk(8u25)仍然是这种情况吗?

java performance garbage-collection nfs

3
推荐指数
1
解决办法
530
查看次数

如何在春季启动时禁用http服务器?

Spring启动文档声称设置server.port = -1会禁用http端点,但对我而言,它的行为与我使用port = 0的行为相同.我想要实现的是批量弹簧启动应用程序,它启动,执行某些操作并关闭.现在它只是坐在那里直到我杀了它.

如何防止它启动http服务器?或者 - 如何从代码中优雅地关闭Spring启动应用程序?

我使用的是版本1.2.4.RELEASE.我在主类上有以下注释:

@Configuration
@ComponentScan
@EnableAutoConfiguration
@EnableCaching
Run Code Online (Sandbox Code Playgroud)

编辑 - 我的依赖项:

compile(
    'redis.clients:sharded-jedis-sentinel-pool:0.2.10.08e7bbe',
    'org.springframework.boot:spring-boot-starter-jdbc',
    'org.springframework.boot:spring-boot-starter-web',
    'mysql:mysql-connector-java:5.1.33',
    'org.flywaydb:flyway-core:3.2.1',
)
Run Code Online (Sandbox Code Playgroud)

没有spring-boot-starter-web spring throws:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.GzipFilterAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.boot.autoconfigure.web.GzipFilterProperties org.springframework.boot.autoconfigure.web.GzipFilterAutoConfiguration.properties; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.http.gzip.CONFIGURATION_PROPERTIES': Initialization of bean failed; nested exception is java.lang.TypeNotPresentException: Type org.springframework.http.HttpMethod not present
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    at …
Run Code Online (Sandbox Code Playgroud)

configuration spring spring-boot

3
推荐指数
2
解决办法
4217
查看次数

Stacktrace与类名中的数字 - 为什么?

当finalizeOperation运行时(在更大的应用程序中生产):

public interface OperationFinalizerHook {
    void onOperationFinalize(Operation operation, Object context);
}
private final List<OperationFinalizerHook> operationFinalizeHooks = new ArrayList<>();
...
public void finalizeOperation(Object context) {
    final Operation operation = getOperation();
    operationFinalizeHooks.forEach(hook -> hook.onOperationFinalize(operation, context));
}
Run Code Online (Sandbox Code Playgroud)

跟随调用树/堆栈跟踪构建:

11 at com.company.SomeClass.lambda$finalizeOperation$0 (SomeClass.java:51)
12 at com.company.SomeClass$$Lambda$135/2085968933.accept (Unknown source)
13 at java.util.ArrayList.forEach (ArrayList.java:1249)
14 at com.company.SomeClass.finalizeOperation (SomeClass.java:51)
Run Code Online (Sandbox Code Playgroud)

我对第12行感兴趣 - 这个名字来自哪里?为什么我会期望一个类的名字随机数?

编辑:以下是Niklas P 提到的博客文章中的代码:

public class Test {
    public static void main(String... args) {
        List<String> names = Arrays.asList("adam", "");
        Stream lengths = names.stream().map(name -> check(name)); …
Run Code Online (Sandbox Code Playgroud)

java jvm java-8

3
推荐指数
1
解决办法
536
查看次数