常见问题
Java FAQ
javac 乱码
强制使用 UTF-8
javac -J-Dfile.encoding=UTF-8环境变量
- JAVA_TOOL_OPTIONS
- java, javac, jar 会用
- 例如
-agentlib:hprof - JVMTI 定义
_JAVA_OPTIONS- 类似 JAVA_TOOL_OPTIONS,但优先级更高
- 针对 Hotspot
- JAVA_OPTS
- 由其他工具使用
- java 不用
- JDK_JAVA_OPTIONS
- jdk9+
- 类似 JAVA_TOOL_OPTIONS,但只有 java 会用
- java
- JAVA_HOME
Property
file.encoding=UTF-8
user.language=en
user.country=US
user.variant=
java.io.tmpdir=
javax.net.ssl.keyStore=
javax.net.ssl.keyStorePassword=
javax.net.ssl.keyStoreType=
javax.net.ssl.trustStore=
javax.net.ssl.trustStorePassword=
javax.net.ssl.trustStoreType=
com.sun.management.jmxremote=选择 JUL 类逻辑
graph TD
Start[选择JUL类] --> KVorV[KV or Value only?]
KVorV --Value--> Duplicate[是否允许重复?]
Duplicate --Yes--> Sync[是否线程同步?]
Duplicate--No-->Ordered[是否有序?]
Ordered--No-->HasSet
Ordered--Yes-->ByInsertOrValue[插入排序还是值排序?]
ByInsertOrValue--Insert-->LinkedHashSet
ByInsertOrValue--Value-->TreeSet
Sync--Yes-->LIFO[LIFO堆栈操作?]
LIFO--Yes-->Stack
LIFO--No-->Vector
Sync --No--> RandomAccess[随机访问?]
RandomAccess--Yes-->ArrayList
RandomAccess --No--> SeqAccess[顺序访问?]
SeqAccess --Yes--> LinkedList
SeqAccess --No--> Queue[队列操作?]
Queue --No--> ArrayList
Queue --Yes--> FastQueue[快速队列?]
FastQueue --No--> LinkedList
FastQueue --Yes--> ArrayDeque
KVorV--KV-->EntryOrdered[有序?]
EntryOrdered--Yes-->EntryOrderedBy[顺序基于?]
EntryOrderedBy--Insert-->LinkedHashMap
EntryOrderedBy--Key-->KVSync[线程同步?]
KVSync--Yes-->HashTable
KVSync--No-->TreeMap
EntryOrdered--No-->Cache[作为缓存/Value构建成本高?]
Cache--Yes-->WeakHashMap
Cache--No-->Equals[equals/==?]
Equals--equals-->HashMap
Equals--==-->IdentityHashMap
Why is generic of a return type erased when there is an unchecked conversion of a method parameter in Java 8?
Proxy performance
stackoverflow.com/q/1856242/1870054
deploy
-Dspring.profiles.active=developmentSPRING_PROFILES_ACTIVE
A fatal error has been detected by the Java Runtime Environment
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00000000000207f6, pid=1, tid=0x00007f9256df8b38
#
# JRE version: OpenJDK Runtime Environment (8.0_345-b01) (build 1.8.0_345-b01)
# Java VM: OpenJDK 64-Bit Server VM (25.345-b01 mixed mode linux-amd64 compressed oops)
# Derivative: IcedTea 3.24.0
# Distribution: Custom build (Tue Nov 8 21:00:08 UTC 2022)
# Problematic frame:
# C 0x00000000000207f6- netty musl
- -Dio.micrometer.shaded.io.netty.transport.noNative=true
- -Dio.grpc.netty.shaded.io.netty.transport.noNative=true
- -Dorg.apache.rocketmq.shaded.io.grpc.netty.shaded.io.netty.transport.noNative=true
- Netty 4.1.77.Final+ 避免 segfaulting
- [netty#11701](- netty/netty#11701GitHub Issuenetty/netty#11701)
apk add gcompat
export LD_PRELOAD=/lib/libgcompat.so.0Unable to get pid of LinuxThreads manager thread
alpine docker 里 java 8 为 pid 1 时出现。
curl -O https://arthas.aliyun.com/arthas-boot.jar
pid=1
touch /proc/${pid}/cwd/.attach_pid${pid} && kill -SIGQUIT ${pid} && sleep 2 && ls /proc/${pid}/root/tmp/.java_pid${pid}
java -jar arthas-boot.jar 1# musl 无法判断线程模型
getconf GNU_LIBPTHREAD_VERSION
# https://github.com/jattach/jattach
apk add jattach
jattach 1 properties- OpenJDK 11+ 修复
- 通过 -XX:+StartAttachListener 可避免问题
- alibaba/arthas#362GitHub Issuealibaba/arthas#362
- docker-library/openjdk#76GitHub Issuedocker-library/openjdk#76
Java Proxy
- properties
- socksProxyHost
- socksProxyPort=1080
- socksNonProxyHosts
- java.net.socks.username
- java.net.socks.password
- http.proxyHost
- http.proxyPort
- http.nonProxyHosts
- e.g.
localhost|host.mydomain.com
- e.g.
- ftp.proxHost
- ftp.proxyPort
- ftp.nonProxyHosts
- Datagrip 支持
?socksProxyHost=&socksProxyPort=
JAVA_FLAGS=-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8087
java %JAVA_FLAGS%// proxySet 似乎是无效的
if (needsProxy()) {
System.getProperties().put("proxySet", "true");
System.getProperties().put("proxyHost", getProxyHost());
System.getProperties().put("proxyPort", getProxyPort());
} else {
System.getProperties().put("proxySet", "false");
System.getProperties().put("proxyHost", "");
System.getProperties().put("proxyPort", "");
}- docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
- docs.oracle.com/javase/6/docs/technotes/guides/net/properties.html
- docs.oracle.com/javase/7/docs/technotes/guides/net/proxies.html
- net 的属性 docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html
gradle
- $HOME/.gradle/gradle.properties
- ./gradle/wrapper/gradle-wrapper.properties
- from objects.githubusercontent.com
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=8080Virtual Thread
- Java 21+
- sychronized -> ReentrantLock
- 支持 Virtual Thread/Loom
- pgjdbc/pgjdbcGitHubpgjdbc/pgjdbc
- pgjdbc/pgjdbc#1951GitHub Issuepgjdbc/pgjdbc#1951
- ebean
- ebean-orm/ebean#2080GitHub Issueebean-orm/ebean#2080
- pgjdbc/pgjdbcGitHubpgjdbc/pgjdbc
- Nats
- nats-io/nats.java#317GitHub Issuenats-io/nats.java#317
- nats-io/nats.java#934GitHub Issuenats-io/nats.java#934
Spring Boot Tomcat
- 性能更好
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatProtocolHandlerCustomizer;
import org.springframework.context.annotation.Bean;
import java.util.concurrent.Executors;
@SpringBootApplication
@Slf4j
public class VirtualthreadApplication {
public static void main(String[] args) {
SpringApplication.run(VirtualthreadApplication.class, args);
}
@Bean
public TomcatProtocolHandlerCustomizer<?> protocolHandlerVirtualThreadExecutorCustomizer() {
return protocolHandler -> {
log.info("Configuring " + protocolHandler + " to use VirtualThreadPerTaskExecutor");
protocolHandler.setExecutor(Executors.newVirtualThreadPerTaskExecutor());
};
}
}String value length exceeds the maximum allowed (20000000, from StreamReadConstraints.getMaxStringLength())
- jackson
- string 字段不能超过 20MB 限制
- 2.15 之前是 5MB
关联信息
反向链接、本文链接的其他页面和外部资料。
反向链接
- arthas笔记 · Unable to get pid of LinuxThreads manager thread · unable to get pid of linuxthreads manager thread
alibaba/arthas · IDEA 插件 · https://plugins.jetbrains.com/plugin/13581-arthas-idea · OGNL 语法 · https://arthas.aliyun.com/doc/dashboard.html
References
GitHub8 条
- alibaba/arthas#362github.com/alibaba/arthas/issues/362
- docker-library/openjdk#76github.com/docker-library/openjdk/issues/76
- ebean-orm/ebean#2080github.com/ebean-orm/ebean/issues/2080
- nats-io/nats.java#317github.com/nats-io/nats.java/issues/317
- nats-io/nats.java#934github.com/nats-io/nats.java/issues/934
- netty/netty#11701github.com/netty/netty/issues/11701
- pgjdbc/pgjdbcgithub.com/pgjdbc/pgjdbc
- pgjdbc/pgjdbc#1951github.com/pgjdbc/pgjdbc/issues/1951
其他外链8 条
- docs.oracle.com/javase/6/docs/technotes/guides/net/properties.htmldocs.oracle.com/javase/6/docs/technotes/guides/net/properties.html
- docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.htmldocs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
- docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.htmldocs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html
- docs.oracle.com/javase/7/docs/technotes/guides/net/proxies.htmldocs.oracle.com/javase/7/docs/technotes/guides/net/proxies.html
- docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.htmldocs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html
- objects.githubusercontent.comobjects.githubusercontent.com/
- stackoverflow.com/q/1856242/1870054stackoverflow.com/q/1856242/1870054
- stackoverflow.com/q/30918308/1870054stackoverflow.com/q/30918308/1870054