小编Zar*_*tra的帖子

java 11 HttpClient导致无休止的SSL循环

我使用的是 java.net.http.HttpClientsendAsync方法.该HttpClient是Singelton内创建一次像这样: HttpClient.newBuilder().build()所以真的没什么特别的.

这些请求可以是POST,GET但我不知道是哪个引起了麻烦.

每天只有几个请求,但有时一个线程使用100%的cpu核心.并不是迫在眉睫,而是在请求完成一段时间后.

所以我做了一个线程转储,甚至有两个无限循环发生,以下2个线程突出:

"HttpClient-4-Worker-5" #144 daemon prio=5 os_prio=0 cpu=511298.10ms elapsed=520.71s tid=0x00007f684403e800 nid=0x2d6b runnable  [0x00007f68ac162000]
   java.lang.Thread.State: RUNNABLE
        at jdk.internal.net.http.common.SSLFlowDelegate$Writer.processData(java.net.http@11.0.2/SSLFlowDelegate.java:771)
        at jdk.internal.net.http.common.SSLFlowDelegate$Writer$WriterDownstreamPusher.run(java.net.http@11.0.2/SSLFlowDelegate.java:645)
        at jdk.internal.net.http.common.SequentialScheduler$CompleteRestartableTask.run(java.net.http@11.0.2/SequentialScheduler.java:147)
        at jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(java.net.http@11.0.2/SequentialScheduler.java:198)
        at jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(java.net.http@11.0.2/SequentialScheduler.java:271)
        at jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(java.net.http@11.0.2/SequentialScheduler.java:224)
        at jdk.internal.net.http.common.SSLFlowDelegate$Writer.triggerWrite(java.net.http@11.0.2/SSLFlowDelegate.java:722)
        at jdk.internal.net.http.common.SSLFlowDelegate.doHandshake(java.net.http@11.0.2/SSLFlowDelegate.java:1024)
        at jdk.internal.net.http.common.SSLFlowDelegate.doClosure(java.net.http@11.0.2/SSLFlowDelegate.java:1094)
        at jdk.internal.net.http.common.SSLFlowDelegate$Reader.unwrapBuffer(java.net.http@11.0.2/SSLFlowDelegate.java:500)
        at jdk.internal.net.http.common.SSLFlowDelegate$Reader.processData(java.net.http@11.0.2/SSLFlowDelegate.java:389)
        - locked <0x00000000fba68950> (a java.lang.Object)
        at jdk.internal.net.http.common.SSLFlowDelegate$Reader$ReaderDownstreamPusher.run(java.net.http@11.0.2/SSLFlowDelegate.java:263)
        at jdk.internal.net.http.common.SequentialScheduler$SynchronizedRestartableTask.run(java.net.http@11.0.2/SequentialScheduler.java:175)
        - locked <0x00000000fbbca3e8> (a java.lang.Object)
        at jdk.internal.net.http.common.SequentialScheduler$CompleteRestartableTask.run(java.net.http@11.0.2/SequentialScheduler.java:147)
        at jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(java.net.http@11.0.2/SequentialScheduler.java:198)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(java.base@11.0.2/ThreadPoolExecutor.java:1128)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(java.base@11.0.2/ThreadPoolExecutor.java:628)
        at java.lang.Thread.run(java.base@11.0.2/Thread.java:834)

   Locked ownable …
Run Code Online (Sandbox Code Playgroud)

java multithreading http http2 java-11

16
推荐指数
3
解决办法
996
查看次数

只为一个字段编写一个Mongo Converter

我有一个案例,我有一个简单的POJO,其中有一个长字段,实际上是一个时间戳.

该字段必须位于由ISODate表示的mongo数据库中.

我可以在整个Pojo中编写一个转换器,但由于它只有25个中的一个字段没有多大意义,并且当字段发生变化或者另外一个被添加时,它是另一个错误点.

有没有办法在默认转换服务之后调用默认转换器服务并更改另外两个服务,这将对性能产生很大影响.或者是否有一个默认的Converter接口来覆盖?

什么是最好的做法?

也许有一个注释可以应用于这个领域?

是的,我也可以写一个LongToDate转换器,但这会影响所有POJO,而不仅仅是这一个.

这里的样本POJO:

public class Person {
   private long someTimestamp;
//getters and setters
}
Run Code Online (Sandbox Code Playgroud)

没有转换器,这将是这样的:

{
    "_id" : ObjectId("52ae8eede4b0249cde22059e"),
    "someTimestamp" : NumberLong(1392714950940)
}
Run Code Online (Sandbox Code Playgroud)

那个结果应该是这样的:

{
    "_id" : ObjectId("52ae8eede4b0249cde22059e"),
    "someTimestamp" : ISODate("2013-12-23T23:00:00.000Z")
}
Run Code Online (Sandbox Code Playgroud)

当这样的时间戳值在嵌套文档中时,所描述的问题变得更加复杂:

{
    "_id" : ObjectId("52ae8eede4b0249cde22059e"),
    "items" : [
        "someTimestamp" : NumberLong(1392714950940)
    ]
}
Run Code Online (Sandbox Code Playgroud)

POJO:

public class Person {
   private Collection<OtherPojoThatHoldsTimestamps> items;
//getters and setters
}
Run Code Online (Sandbox Code Playgroud)

也许我应该提到我使用Spring来实现这一目标.(http://projects.spring.io/spring-data-mongodb/)

java mongodb spring-data

12
推荐指数
3
解决办法
2759
查看次数

模拟一个类的所有实例

我知道这通常是一种不好的做法,但就我而言,这是必要的.

我有一个案例,Enum持有一个类来获取一些信息.这样Enum就可以在其构造函数中创建该calss的实例.

public enum MyEnum {
    CONSTANT(new MyImpl());

    private final MyImpl myImpl;

    private MyEnum(final MyImpl impl) {
        this.myImpl = impl;
    }

    public void sayHello() {
        System.out.println(this.myImpl.getSomethingToSay());
    }

}
Run Code Online (Sandbox Code Playgroud)

MyImpl.java 只是一个具有返回String的单个方法的类.

public class MyImpl {

    public String getSomethingToSay() {
        return "Hello!";
    }

}
Run Code Online (Sandbox Code Playgroud)

现在最后进行单元测试:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.testng.PowerMockTestCase;

@RunWith(MockitoJUnitRunner.class)
@PrepareForTest({ MyImpl.class, MyEnum.class })
public class MyEnumTest extends PowerMockTestCase {
    @Test
    public void testSmth2() throws Exception {
        MyImpl impl = Mockito.mock(MyImpl.class);
        Mockito.when(impl.getSomethingToSay()).thenReturn("It …
Run Code Online (Sandbox Code Playgroud)

java unit-testing enumeration mocking mockito

11
推荐指数
1
解决办法
2万
查看次数

断言复杂对象时的Junit最佳实践

我正在为遗留系统编写很多JUnit测试.

我经常会提出这样的问题:断言复杂对象的最佳方法是什么?

这是我目前的代码

public class SomeParserTest {

    @Test
    public void testParse() throws Exception {
        final SomeParser someParser = new SomeParser();
        someParser.parse("string from some file");

        final List<Result> listOfResults = someParser.getResults();
        assertThat(listOfResults, hasSize(5));

        assertResult(listOfResults.get(0), "20151223", 2411189L, isEmptyOrNullString(), "2.71", "16.99");
        assertResult(listOfResults.get(1), "20151229", 2411190L, isEmptyOrNullString(), "2.86", "17.9");
        assertResult(listOfResults.get(2), "20151229", 2411191L, is("1.26"), ".75", "23.95");
        assertResult(listOfResults.get(3), "20151229", 2411192L, is("2.52"), "1.5", "47.9");
        assertResult(listOfResults.get(4), "20151229", 2411193L, isEmptyOrNullString(), "2.71", "16.99");

        final List<SubResult> listofSubResuls = someParser.getSubResultOf(listOfResults.get(0));
        assertThat(listofSubResuls, hasSize(1));
        assertSubResult(listofSubResuls.get(0), 12.5D, "20151223", 1L, 14.87D, 16.99D, 0L, null, 67152L, "20151223", "2", …
Run Code Online (Sandbox Code Playgroud)

java junit hamcrest

9
推荐指数
2
解决办法
2051
查看次数

无法使用Java 8修改package-info.java的注释

我正面临一个问题,我必须修改包信息.

package-info.java

@javax.xml.bind.annotation.XmlSchema(namespace = "http://some.url/soap/style/document_literal")
package org.example.wsdl.wsdl;
Run Code Online (Sandbox Code Playgroud)

以下代码适用于1.7.0_45.

//          do not load any classes before, this could break the following code.
            Class<?> pkgInfo = Class.forName("org.example.wsdl.package-info", true, NameSpaceModifier.class.getClassLoader());
            Field field = Class.class.getDeclaredField("annotations");
            field.setAccessible(true);

            final XmlSchema oldAnnotation = (XmlSchema) pkgInfo.getAnnotations()[0];
            logger.debug("Old Annotation namespace value was: " + oldAnnotation.namespace());
            XmlSchema newAnnotation = new XmlSchema() {

                @Override
                public XmlNs[] xmlns() {
                    return oldAnnotation.xmlns();
                }

                @Override
                public String namespace() {
                    return "newNs";
                }

                @Override
                public XmlNsForm elementFormDefault() {
                    return oldAnnotation.elementFormDefault();
                }

                @Override
                public XmlNsForm attributeFormDefault() …
Run Code Online (Sandbox Code Playgroud)

java reflection javassist

8
推荐指数
1
解决办法
1418
查看次数

不能在Git中推送标签

我无法在我的git远程存储库中推送带注释的标签.所有访问权限都在gerrit中提供.例如.[参考文献/*]

我正在使用以下命令创建标记

git tag -a v1.0 -m 'Base Version' 712d77e
Run Code Online (Sandbox Code Playgroud)

当我尝试使用以下命令推送时

git push origin v1.0 
Run Code Online (Sandbox Code Playgroud)

要么

git push origin --tags
Run Code Online (Sandbox Code Playgroud)

我收到以下错误.

Counting objects: 1, done.
Writing objects: 100% (1/1), 157 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
remote: Processing changes: refs: 1, done
To ssh://...
! [remote rejected] v1.0 -> v1.0 (prohibited by Gerrit)
error: failed to push some refs to 'ssh://...'
Run Code Online (Sandbox Code Playgroud)

请让我知道如何在存储库中推送标签.

谢谢....

git git-push gerrit

7
推荐指数
2
解决办法
2万
查看次数

弹簧启动与s​​pring-ws -SOAP端点无法访问

我正在玩spring-boot,我遇到了一个问题.创建RESTful Web服务非常简单.但我无法使用spring-boot运行soap服务.

实际上我的项目有spring-boot-starter-web依赖.

是否需要额外的sprint-boot-starter尚不存在?

有什么办法吗?如果我有一个SOAP服务的web.xml,我可以在初始化过程中以某种方式包含它吗?我知道类似的问题已经存在,但它并没有解决我的问题,因为那里的问题是基于spring-web.所以我认为我的问题在其他地方.

我的soap-webservice的端点看起来像这样:

@Endpoint
public class MyEndpoint {


    @PayloadRoot(localPart = "myRequest", namespace = "my.ns")
    @ResponsePayload
    public TResponse logRequest(@RequestPayload final TRequest request) {
        //some code
    }
//more methods
}
Run Code Online (Sandbox Code Playgroud)

端点在xml中是奇怪的,xml由spring-boot通过ImportResource注释加载.

所以我的入门级看起来像这样:

@Configuration
@EnableAutoConfiguration
@ImportResource({ "classpath:/my/pack/app.xml" }) //soap-endpoint is configured here. 
public class Example {

    public static void main(final String[] args) {
        SpringApplication.run(Example.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

端点的配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:web-services="http://www.springframework.org/schema/web-services"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services.xsd …
Run Code Online (Sandbox Code Playgroud)

java spring soap web-services spring-boot

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

为什么休眠 4 不再有 SessionFactoryUtils#applyTransactionTimeout

嗨,我正在将遗留应用程序迁移到 spring 4.x 和 hibernate 4.2.x。

直到现在一切都很顺利。

使用 hibernate 3 和 spring 3,您可以使用 org.springframework.orm.hibernate3.SessionFactoryUtils#applyTransactionTimeout(queryObject, sessionFactory)

SessionFactoryUtils对休眠4没有该方法。为什么?是不是已经不需要了?我必须以不同的方式设置它吗?

java spring hibernate

5
推荐指数
0
解决办法
158
查看次数

使用Jackson序列化自定义地图

我想将自定义Map序列化为JSON.

实现map接口的类如下:

public class MapImpl extends ForwardingMap<String, String> {
//ForwardingMap comes from Guava
    private String                  specialInfo;

    private HashMap<String, String> delegate;

    @Override
    protected Map<String, String> delegate() {
        return this.delegate;
    }
// some getters....
 }
Run Code Online (Sandbox Code Playgroud)

如果我现在打电话

    ObjectMapper mapper = new ObjectMapper();
    mapper.writeValue(new File("/somePath/myJson.json"), objectOfMapImpl);
Run Code Online (Sandbox Code Playgroud)

杰克逊将序列化地图并忽略变量 specialInfo

我尝试了一些自定义实现的东西,JsonSerializer但我最终得到了这个片段:

    ObjectMapper mapper = new ObjectMapper();

    SimpleModule module = new SimpleModule("someModule");



       module.addSerializer(CheapestResponseDates.class, new JsonSerializer<MapImpl>() {

            @Override
            public void serialize(final MapImpl value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException {
CheapestResponseDurations.class);
// how …
Run Code Online (Sandbox Code Playgroud)

java serialization json jackson

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

Jenkins git 插件:无法识别 Peer 的证书颁发者

在尝试连接到通过 https 托管的存储库时,我在使用 jenkins git 插件时遇到了问题。

Baue in Arbeitsbereich /opt/jenkins/jobs/TestJob2/workspace
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://my.host.de/group/project # timeout=10
Fetching upstream changes from https://my.host.de/group/project
 > git --version # timeout=10
using GIT_ASKPASS to set credentials Jenkins at my.host.de
 > git fetch --tags --progress https://my.host.de/group/project +refs/heads/*:refs/remotes/origin/*
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from https://my.host.de/group/project
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:766)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1022)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1053)
    at hudson.scm.SCM.checkout(SCM.java:485)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1269)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:607)
    at …
Run Code Online (Sandbox Code Playgroud)

git ssl jenkins

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

内存消耗 java.util.Date vs java.time.LocalDate vs org.joda.time.DateTime

我想知道内存消耗

  • java.util.Date
  • java.time.LocalDate
  • org.joda.time.DateTime

我需要创建一堆有一些日期的对象,今天它们是很长的时间戳,但这不太好,并且会在另一端创建 CPU 负载,因为我需要日期。

所以我的问题是:有可用的统计数据吗?大概如何衡量这样的事情?

java memory datetime java-8

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