java-9

How to log request/response using java.net.http.HttpClient?

℡╲_俬逩灬. 提交于 2019-12-18 15:35:42
问题 The HttpClient introduced experimentally in Java 9 is now stable in Java 11, but not surprisingly, very few projects seem to actually use it. Documentation is almost non-existing. One of the most commons asks while making a HTTP call is logging of request/response. How would you do that using the HttpClient , without of course, logging it manually in every single call? Is there an interceptor mechanism like that offered by all other HTTP clients? 回答1: If we look at jdk.internal.net.http

Is String Deduplication feature of the G1 garbage collector enabled by default?

本秂侑毒 提交于 2019-12-18 12:56:16
问题 JEP 192: String Deduplication in G1 implemented in Java 8 Update 20 added the new String deduplication feature: Reduce the Java heap live-data set by enhancing the G1 garbage collector so that duplicate instances of String are automatically and continuously deduplicated. The JEP page mentions that a command-line option UseStringDeduplication (bool) allows the dedup feature to be enabled or disabled. But the JEP page does not go so far as to indicate the default. ➠ Is the dedup feature ON or

How should I name my Java 9 module?

好久不见. 提交于 2019-12-18 12:47:23
问题 Suppose I have a library with groupId = org.abc and artifactId = myLibrary . What is the recommended name for the module name: myLibrary or org.abc.myLibrary ? Is there any official guide for a naming scheme? 回答1: For a while there were two different opinions on your question but during the development of the module system, the community settled on the reverse DNS approach. Unique Module Names - Reverse DNS Here, the assumption is that module names should be globally unique. Given that goal,

ImmutableCollections SetN implementation detail

ⅰ亾dé卋堺 提交于 2019-12-18 12:19:05
问题 I have sort of a hard time understanding an implementation detail from java-9 ImmutableCollections.SetN ; specifically why is there a need to increase the inner array twice. Suppose you do this: Set.of(1,2,3,4) // 4 elements, but internal array is 8 More exactly I perfectly understand why this is done (a double expansion) in case of a HashMap - where you never (almost) want the load_factor to be one. A value of !=1 improves search time as entries are better dispersed to buckets for example.

Is it possible to load and unload jdk and custom modules dynamically in Java 9?

こ雲淡風輕ζ 提交于 2019-12-18 12:15:39
问题 I am beginner in JPMS and can't understand its dynamism. For example, in current JVM instance moduleA.jar is running. moduleA requires only java.base module. Now, I want to load dynamically moduleB.jar that needs java.sql module and moduleC.jar execute some code from moduleB unload moduleB , java.sql , moduleC from JVM and release all resources. Can it be done in Java 9 module system? 回答1: This is an advanced topic. At a high-level, the module system is not dynamic in the sense that

Java 9 + maven + junit: does test code need module-info.java of its own and where to put it?

坚强是说给别人听的谎言 提交于 2019-12-18 11:17:30
问题 Let's say I have a Java project using Maven 3 and junit. There are src/main/java and src/test/java directories which contain main sources and test sources, respectively (everything is standard). Now I want to migrate the project to Java 9. src/main/java content represents Java 9 module; there is com/acme/project/module-info.java looking approximately like this: module com.acme.project { require module1; require module2; ... } What if test code needs module-info.java of its own? For example,

How to extract the file jre-9/lib/modules?

[亡魂溺海] 提交于 2019-12-18 11:08:50
问题 In JRE-9/lib directory (at least on Windows), there is a new file called modules whose size is about 107 MB. Is it possible to extract that file or maybe list java modules within it? I can see that a new tool called jmod is available at jdk-9/bin/jmod.exe , but that is for reading .jmod files which is located at jdk-9/jmods and it cannot read the file modules . 回答1: The modules file is a container file. It's internal to the JDK and the format is not documented (it may change at any time). For

newInstance vs new in jdk-9/jdk-8 and jmh

 ̄綄美尐妖づ 提交于 2019-12-18 10:32:43
问题 I've seen a lot of threads here that compare and try to answer which is faster: newInstance or new operator . Looking at the source code, it would seem that newInstance should be much slower , I mean it does so many security checks and uses reflection. And I've decided to measure, first running jdk-8. Here is the code using jmh . @BenchmarkMode(value = { Mode.AverageTime, Mode.SingleShotTime }) @Warmup(iterations = 5, time = 2, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 5, time =

Mockito, Java 9 and java.lang.ClassNotFoundException: sun.reflect.ReflectionFactory

余生颓废 提交于 2019-12-18 06:02:07
问题 My project is a Wildfly 13 application which uses Mockito testing library. The app is not using Java 9 module structure. As long as the server ran on Java 8 the tests worked fine, but once we upgraded to Java 9 they failed with the following exception: org.objenesis.ObjenesisException: java.lang.ClassNotFoundException: sun.reflect.ReflectionFactory from [Module "test.war" from Service Module Loader] at test.war//org.objenesis.instantiator.sun.SunReflectionFactoryHelper

final variables are not functioning well in jshell

好久不见. 提交于 2019-12-18 05:02:23
问题 I am working with jshell of JDK9. I just created a final variable and assigned a value to it. And in the next line i just modified the value. And to my surprise, there was no error when modifying the final variables. Here is the code snippets: jshell> final int r = 0; | Warning: | Modifier 'final' not permitted in top-level declarations, ignored | final int r = 0; | ^---^ r ==> 0 jshell> r = 1; r ==> 1 jshell> System.out.println("r = "+r) r = 1 Is it what is expected from jshell? or there is