Cassandra 和 Java 9 - ThreadPriorityPolicy=42 超出允许范围
Cassandra and Java 9 - ThreadPriorityPolicy=42 is outside the allowed range
最近我从官方网站安装了 JDK 9 和 Apache Cassandra。但是现在当我在前台启动 cassandra 时,我收到这条消息:
apache-cassandra-3.11.1/bin$ ./cassandra -f
[0.000s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:/home/mmatak/monero/apache-cassandra-3.11.1/logs/gc.log instead.
intx ThreadPriorityPolicy=42 is outside the allowed range [ 0 ... 1 ]
Improperly specified VM option 'ThreadPriorityPolicy=42'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
到目前为止我还没有找到任何解决方案。 Java 9 和 Cassandra 可能还不兼容吗?这也是提到的问题 - #CASSANDRA-13107
但我不确定如何"remove the flag"?在哪里可以覆盖或删除此标志?
在您的 conf
目录中有一个 jvm.options
设置它:
我遇到了完全相同的问题:
如果您可以选择,使用 Java 8 而不是 9 是解决问题的最简单方法。
@Martin Matak 只需注释掉 conf/jvm.options
文件中的那一行:
########################
# GENERAL JVM SETTINGS #
########################
# allows lowering thread priority without being root on linux - probably
# not necessary on Windows but doesn't harm anything.
# see http://tech.stolsvik.com/2010/01/linux-java-thread-priorities-workaround.html
**#-XX:ThreadPriorityPolicy=42**
问题的解决方案
此异常的原因
- 多个 JDK 版本 运行ning,可能 JDK9,JDK 10 导致此异常。
- 将路径设置为点 JDK 仅限 8 版本。
- 目前需要 cassandra 3.1 运行 大于 jdk 8。
Cassandra-Conf 文件的更改(/opt/apache-cassandra-3.11.2/conf/cassandra-env.sh)
4.If你想使用更高的JDK版本,根据你的OS更新系统路径变量。
设置以下环境变量解决了 MAC 中的问题
export JAVA8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
如果您使用的是 macOS 并通过 Homebrew 安装,则来自 :文件位于 local/etc/cassandra/jvm.options
.
关于 -XX:ThreadPriorityPolicy
的一些背景知识。
这些是源代码中记录的值。
0 : Normal.
VM chooses priorities that are appropriate for normal
applications. On Solaris NORM_PRIORITY and above are mapped
to normal native priority. Java priorities below
NORM_PRIORITY map to lower native priority values. On
Windows applications are allowed to use higher native
priorities. However, with ThreadPriorityPolicy=0, VM will
not use the highest possible native priority,
THREAD_PRIORITY_TIME_CRITICAL, as it may interfere with
system threads. On Linux thread priorities are ignored
because the OS does not support static priority in
SCHED_OTHER scheduling class which is the only choice for
non-root, non-realtime applications.
1 : Aggressive.
Java thread priorities map over to the entire range of
native thread priorities. Higher Java thread priorities map
to higher native thread priorities. This policy should be
used with care, as sometimes it can cause performance
degradation in the application and/or the entire system. On
Linux this policy requires root privilege.
换句话说:默认的正常设置导致在Linux.[=15=上忽略线程优先级]
现在 someone 在代码中发现了一个错误,它禁用了“is root?”检查 1 以外的值,但仍会尝试为 0 以外的每个值设置线程优先级。
除非运行作为root,否则只能降低线程优先级。因此,虽然不完美,但与完全无法控制优先级相比,这是一个很大的进步。
从 Java 9 开始,像这样的命令行参数开始变得 checked,这个 hack 停止工作.
Fwiw, on Java 11/Linux, 我可以将参数设置为 1
而不是 root, 并设置线程优先级确实有效果。所以与此同时,有些事情发生了变化,至少最近的 JVM 发生了变化,这种 hack 似乎不再需要了。
最近我从官方网站安装了 JDK 9 和 Apache Cassandra。但是现在当我在前台启动 cassandra 时,我收到这条消息:
apache-cassandra-3.11.1/bin$ ./cassandra -f
[0.000s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:/home/mmatak/monero/apache-cassandra-3.11.1/logs/gc.log instead.
intx ThreadPriorityPolicy=42 is outside the allowed range [ 0 ... 1 ]
Improperly specified VM option 'ThreadPriorityPolicy=42'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
到目前为止我还没有找到任何解决方案。 Java 9 和 Cassandra 可能还不兼容吗?这也是提到的问题 - #CASSANDRA-13107
但我不确定如何"remove the flag"?在哪里可以覆盖或删除此标志?
在您的 conf
目录中有一个 jvm.options
设置它:
我遇到了完全相同的问题:
如果您可以选择,使用 Java 8 而不是 9 是解决问题的最简单方法。
@Martin Matak 只需注释掉 conf/jvm.options
文件中的那一行:
########################
# GENERAL JVM SETTINGS #
########################
# allows lowering thread priority without being root on linux - probably
# not necessary on Windows but doesn't harm anything.
# see http://tech.stolsvik.com/2010/01/linux-java-thread-priorities-workaround.html
**#-XX:ThreadPriorityPolicy=42**
问题的解决方案
此异常的原因
- 多个 JDK 版本 运行ning,可能 JDK9,JDK 10 导致此异常。
- 将路径设置为点 JDK 仅限 8 版本。
- 目前需要 cassandra 3.1 运行 大于 jdk 8。
Cassandra-Conf 文件的更改(/opt/apache-cassandra-3.11.2/conf/cassandra-env.sh)
4.If你想使用更高的JDK版本,根据你的OS更新系统路径变量。
设置以下环境变量解决了 MAC 中的问题
export JAVA8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
如果您使用的是 macOS 并通过 Homebrew 安装,则来自 local/etc/cassandra/jvm.options
.
关于 -XX:ThreadPriorityPolicy
的一些背景知识。
这些是源代码中记录的值。
0 : Normal.
VM chooses priorities that are appropriate for normal
applications. On Solaris NORM_PRIORITY and above are mapped
to normal native priority. Java priorities below
NORM_PRIORITY map to lower native priority values. On
Windows applications are allowed to use higher native
priorities. However, with ThreadPriorityPolicy=0, VM will
not use the highest possible native priority,
THREAD_PRIORITY_TIME_CRITICAL, as it may interfere with
system threads. On Linux thread priorities are ignored
because the OS does not support static priority in
SCHED_OTHER scheduling class which is the only choice for
non-root, non-realtime applications.
1 : Aggressive.
Java thread priorities map over to the entire range of
native thread priorities. Higher Java thread priorities map
to higher native thread priorities. This policy should be
used with care, as sometimes it can cause performance
degradation in the application and/or the entire system. On
Linux this policy requires root privilege.
换句话说:默认的正常设置导致在Linux.[=15=上忽略线程优先级]
现在 someone 在代码中发现了一个错误,它禁用了“is root?”检查 1 以外的值,但仍会尝试为 0 以外的每个值设置线程优先级。
除非运行作为root,否则只能降低线程优先级。因此,虽然不完美,但与完全无法控制优先级相比,这是一个很大的进步。
从 Java 9 开始,像这样的命令行参数开始变得 checked,这个 hack 停止工作.
Fwiw, on Java 11/Linux, 我可以将参数设置为 1
而不是 root, 并设置线程优先级确实有效果。所以与此同时,有些事情发生了变化,至少最近的 JVM 发生了变化,这种 hack 似乎不再需要了。