Cassandra和Java 9 - ThreadPriorityPolicy = 42超出允许范围

时间:2017-10-25 15:17:52

标签: cassandra jvm java-9 jvm-arguments

最近我从官方网站安装了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

但我不确定如何“删除旗帜”?在哪里可以覆盖或删除此标志?

7 个答案:

答案 0 :(得分:6)

我有完全相同的问题: Can't start Cassandra (Single-Node Cluster on CentOS7)

如果它是一个选项,使用Java 8而不是9,是解决问题的最简单方法。

答案 1 :(得分:6)

@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**

答案 2 :(得分:3)

设置以下环境变量可解决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

答案 3 :(得分:1)

-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.

换句话说:默认的 Normal 设置导致在Linux上线程优先级被忽略。

现在someone在代码中发现了一个错误,该错误禁用了“是root?”。检查1以外的值,但仍会尝试为0以外的每个值设置线程优先级。

除非以超级用户身份运行,否则只能降低降低线程优先级。因此,尽管并不完美,但与根本无法控制优先级相比,这是一个很大的进步。

从Java 9开始,像这样的命令行参数开始获得checked,并且此hack停止工作。

首先,在Java 11 / Linux上,我可以将参数设置为1而不需要root用户,并且设置线程优先级确实会起作用。因此,在此期间,至少在最近的JVM中,已经发生了一些变化,并且这种黑客似乎不再必要。

答案 4 :(得分:0)

答案 5 :(得分:0)

问题的解决方案

此例外的原因

  1. 正在运行的多个JDK版本,可能是JDK9,JDK 10导致了此异常。
  2. 设置仅指向JDK 8版本的路径。
  3. 当前,cassandra 3.1仅希望运行于jdk 8以上。

更改Cassandra-Conf文件(/opt/apache-cassandra-3.11.2/conf/cassandra-env.sh)

 4.如果要使用更高的JDK版本,请根据您的OS更新系统路径变量。

答案 6 :(得分:0)

如果您使用的是MacOS操作系统并通过Homebrew安装,则从Jay's answer开始:该文件位于local/etc/cassandra/jvm.options