假设我有这个代码(我认为这无关紧要,但以防万一):
public class AtomicJDK9 {
static AtomicInteger ai = new AtomicInteger(0);
public static void main(String[] args) {
int sum = 0;
for (int i = 0; i < 30_000; ++i) {
sum += atomicIncrement();
}
System.out.println(sum);
}
public static int atomicIncrement() {
ai.getAndAdd(12);
return ai.get();
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我如何调用它(使用java-9):
java -XX:+UnlockDiagnosticVMOptions
-XX:-TieredCompilation
-XX:+PrintIntrinsics
AtomicJDK9
Run Code Online (Sandbox Code Playgroud)
我想要找出的是什么方法被内在代码所取代.第一个被击中(在不安全的内部):
@HotSpotIntrinsicCandidate
public final int getAndAddInt(Object o, long offset, int delta) {
int v;
do {
v = getIntVolatile(o, offset);
} while (!weakCompareAndSwapIntVolatile(o, offset, v, v + …Run Code Online (Sandbox Code Playgroud) 我目前正在测试将现有应用程序迁移到Jigsaw Modules.我的一个模块使用ElasticSearch及其Groovy插件.
不幸的是,他们共享一个拆分包,所以mvn install给我:
x从lang.groovy和elasticsearch读取包org.elasticsearch.script.groovy
对于描述符中的每个必需模块,其中x是每个模块的名称.
我假设一个较新的elasticsearch版本将在Java 9最终版本的时候取消拆分包,但是通常有一种方法来处理遗留依赖项中的拆分包吗?
我希望能够在类路径而不是模块路径上有那些,但是在邮件列表上阅读这个对话后,似乎没有办法告诉Maven编译器这样做.
maven 3.3.9 - maven-compiler-plugin 3.6.0 - jdk9-ea + 149 - elasticsearch 2.3.3
maven java-platform-module-system maven-compiler-plugin java-9
在scala中,这些方法工作正常,但在java9中,dropWhile的工作方式与我想的不同.
以下是takeWhile的示例
Stream.of("a", "b", "c", "de", "f", "g", "h")
.peek(System.out::println)
.takeWhile(s -> s.length() <= 1)
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
输出很好:a,b,c,de,[a,b,c]它不处理"de"之后的元素,所以它按预期工作
但是DropWhile以我期望的不同方式工作:
Stream.of("a", "b", "c", "de", "f", "g", "h")
.peek(s -> System.out.print(s + ", "))
.dropWhile(s -> s.length() <= 1)
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
输出为:a,b,c,de,f,g,h,[de,f,g,h]
因此它不会在"de"元素之后停止,它正在处理整个集合.
为什么要处理整个系列?我知道,需要采取所有元素并将其收集到列表中,但不应该在"de"元素之后停止处理吗?
我已经将java从8更新到9-ea并从2.13更新为3.4.1.以下是gradle --version输出.
------------------------------------------------------------
Gradle 3.4.1
------------------------------------------------------------
Build time: 2017-03-03 19:45:41 UTC
Revision: 9eb76efdd3d034dc506c719dac2955efb5ff9a93
Groovy: 2.4.7
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 9-ea (Oracle Corporation 9-ea+158)
OS: Linux 4.8.0-36-generic amd64
Run Code Online (Sandbox Code Playgroud)
遇到以下错误时编译:
FAILURE: Build failed with an exception.
* What went wrong:
java.lang.ExceptionInInitializerError (no error message)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Run Code Online (Sandbox Code Playgroud)
输出gradle --stacktrace如下:
java.lang.ExceptionInInitializerError
at org.gradle.initialization.DefaultClassLoaderRegistry.restrictTo(DefaultClassLoaderRegistry.java:40) …Run Code Online (Sandbox Code Playgroud) 在Spring 5.0.0.RC4参考文档中,它说:
Publisher或Flow.Publisher - 支持实现Reactive Streams Publisher的任何类型.
https://docs.spring.io/spring/docs/5.0.0.RC4/spring-framework-reference/reactive-web.html#webflux
但是当我创建一个基于Spring 5.0.0.RC4的简单项目时,我Flow.Publisher在控制器中返回时失败了.似乎Flow.Publisher杰克逊无法将其序列化.
org.springframework.core.codec.CodecException: Type definition error: [simple type, class java.util.concurrent.ForkJoinPool$DefaultForkJoinWorkerThreadFactory]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class java.util.concurrent.ForkJoinPool$DefaultForkJoinWorkerThreadFactory and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.concurrent.SubmissionPublisher["executor"]->java.util.concurrent.ForkJoinPool["factory"])
at org.springframework.http.codec.json.AbstractJackson2Encoder.encodeValue(AbstractJackson2Encoder.java:132)
at org.springframework.http.codec.json.AbstractJackson2Encoder.lambda$encode$0(AbstractJackson2Encoder.java:96)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:107)
at reactor.core.publisher.FluxJust$WeakScalarSubscription.request(FluxJust.java:91)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:156)
at org.springframework.http.server.reactive.ChannelSendOperator$WriteBarrier.onSubscribe(ChannelSendOperator.java:143)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onSubscribe(FluxMapFuseable.java:90)
at reactor.core.publisher.FluxJust.subscribe(FluxJust.java:68)
at reactor.core.publisher.FluxMapFuseable.subscribe(FluxMapFuseable.java:63)
at org.springframework.http.server.reactive.ChannelSendOperator.subscribe(ChannelSendOperator.java:76)
at reactor.core.publisher.MonoOnErrorResume.subscribe(MonoOnErrorResume.java:44)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:150)
at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1068)
at reactor.core.publisher.MonoFlatMap$FlatMapInner.onNext(MonoFlatMap.java:241)
at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:72)
at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.onNext(FluxPeekFuseable.java:198) …Run Code Online (Sandbox Code Playgroud) A week ago, every project I had was working normally, but when I updated my Eclipse to the Oxygen version and installed JDK-9, things have come strange. When I try to use Strings, after some time (more like every time I save the project) the compiler throws me an error for every String in my project.
So I've tried importing java.lang.String to see if it fix the …
我有一个module-info.java看起来像的文件 -
module foo.microservice {
requires spring.core;
requires spring.beans;
requires spring.context;
requires java.sql; // required for Spring Annotation based configuration :(
opens foo.microservice.configuration to spring.core;
opens foo.microservice.internal.services to spring.beans;
opens foo.microservice.internal.controllers to spring.beans;
exports foo.microservice.configuration;
exports foo.microservice.controllers;
exports foo.microservice.models;
exports foo.microservice.services;
}
Run Code Online (Sandbox Code Playgroud)
我希望有可能允许Spring访问所有内部包,而无需将每个包显式添加到module-info.java.
有没有办法让一个更通用的opens语句允许所有我的内部包(和子包)可访问spring.beans?
编辑:我分析了给定的答案.特别是我测试了Till Brychcy的假设,这个假设似乎成立了,但开了更多问题.在以下大分隔符之后,我在问题的最后添加了分析:"-----------分析Till Brychcy的答案----------"
它以某种方式编译并在IJ中运行,但mvn clean install无法编译测试
我有一个带有2个模块的java 9 maven项目:apimod和clientmod.模块clientmod依赖于模块apimod(这些模块都是Maven模块和Java 9模块).
此外,我希望模块clientmod不仅可以重用生产代码apimod,还可以重用测试代码.这是一个常见的模式,我多次使用Java 8.使用Java 9(它与Java 10相同)它也可以正常工作,只要我不声明module-info.java(也就是说,只要我不这样做)运行模块系统).
但是一旦我这样做,启用测试依赖性似乎会禁用生产依赖:( api.Base一src/main类模块apimod)不再可见client.test.DerivedTest(一src/test类模块clientmod).测试不再编译.
这是Maven还是Java 9中的错误?这是最新版本:Java 9.0.4(与Java 10相同),Maven 3.5.3,maven-compiler-plugin 3.7.0
源代码位于:
git clone https://github.com/vandekeiser/wires.git
Run Code Online (Sandbox Code Playgroud)
我对分支中的测试失败问题进行了"二分法":
git checkout MINIMIZE_ISSUE
`mvn clean install`
Run Code Online (Sandbox Code Playgroud)
- > BUILD FAIL(测试中的编译错误clientmod)
我希望模块clientmod不仅可以重用生产代码,apimod还可以重用测试代码.使用Maven,你就像那样(clientmod/pom.xml):
<dependency>
<groupId>fr.cla</groupId>
<artifactId>apimod</artifactId> …Run Code Online (Sandbox Code Playgroud) VarHandle显示以下错误 -
Exception in thread "main" java.lang.NoSuchMethodError: VarHandle.compareAndSet(VarHandleExample,int,int)void
at java.base/java.lang.invoke.MethodHandleNatives.newNoSuchMethodErrorOnVarHandle(MethodHandleNatives.java:492)
at java.base/java.lang.invoke.MethodHandleNatives.varHandleOperationLinkerMethod(MethodHandleNatives.java:445)
at java.base/java.lang.invoke.MethodHandleNatives.linkMethodImpl(MethodHandleNatives.java:378)
at java.base/java.lang.invoke.MethodHandleNatives.linkMethod(MethodHandleNatives.java:366)
at j9.VarHandleExample.update(VarHandleExample.java:23)
at j9.VarHandleExample.main(VarHandleExample.java:14)
Run Code Online (Sandbox Code Playgroud)
我的计划是:
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
public class VarHandleExample {
public int publicTestVariable = 10;
public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
VarHandleExample e= new VarHandleExample();
e.update();
}
public void update() throws NoSuchFieldException, IllegalAccessException {
VarHandle publicIntHandle = MethodHandles.lookup()
.in(VariableHandlesTest.class)
.findVarHandle(VarHandleExample.class, "publicTestVariable", int.class);
publicIntHandle.compareAndSet(this, 10, 100); // CAS
}
}
Run Code Online (Sandbox Code Playgroud) 我在JShell中编写了一个Java方法,现在我想调试它.我想设置断点或者至少逐行执行.JShell有这些调试功能吗?
java-9 ×10
java ×8
maven ×2
spring ×2
debugging ×1
eclipse ×1
gradle ×1
java-10 ×1
java-platform-module-system ×1
java-stream ×1
jshell ×1
jvm ×1
methodhandle ×1
module-info ×1
scala ×1