日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > windows >内容正文

windows

java设置属性的取值范围是多少_jvm-Java系统属性的范围

發(fā)布時(shí)間:2023/12/13 windows 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java设置属性的取值范围是多少_jvm-Java系统属性的范围 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

系統(tǒng)屬性的范圍

至少?gòu)拈喿xProperties方法的API規(guī)范后,我無(wú)法獲得關(guān)于是否由JVM的所有實(shí)例共享系統(tǒng)屬性的答案。

為了找出答案,我編寫(xiě)了兩個(gè)快速程序,這些程序?qū)⑹褂孟嗤逆I但不同的值通過(guò)Properties設(shè)置系統(tǒng)屬性:

class T1 {

public static void main(String[] s) {

System.setProperty("dummy.property", "42");

// Keep printing value of "dummy.property" forever.

while (true) {

System.out.println(System.getProperty("dummy.property"));

try {

Thread.sleep(500);

} catch (Exception e) {}

}

}

}

class T2 {

public static void main(String[] s) {

System.setProperty("dummy.property", "52");

// Keep printing value of "dummy.property" forever.

while (true) {

System.out.println(System.getProperty("dummy.property"));

try {

Thread.sleep(500);

} catch (Exception e) {}

}

}

}

(請(qǐng)注意,運(yùn)行上面的兩個(gè)程序?qū)⑹顾鼈兿萑霟o(wú)限循環(huán)!)

事實(shí)證明,使用兩個(gè)單獨(dú)的Properties進(jìn)程運(yùn)行兩個(gè)程序時(shí),在一個(gè)JVM進(jìn)程中設(shè)置的屬性值不會(huì)影響另一個(gè)JVM進(jìn)程的值。

我應(yīng)該補(bǔ)充一點(diǎn),這是使用Sun的JRE 1.6.0_12的結(jié)果,并且至少在API規(guī)范中沒(méi)有定義此行為(或者我找不到它),行為可能會(huì)有所不同。

是否有任何工具可以監(jiān)視運(yùn)行時(shí)更改

據(jù)我所知。 但是,如果確實(shí)需要檢查系統(tǒng)屬性是否有更改,則可以一次保存Properties的副本,并將其與另一個(gè)對(duì)System.getProperties的調(diào)用進(jìn)行比較-畢竟Properties是Properties的子類(lèi), 因此比較將以類(lèi)似方式執(zhí)行。

下面的程序演示了一種檢查系統(tǒng)屬性是否已更改的方法。 可能不是一個(gè)優(yōu)雅的方法,但是它似乎可以完成它的工作:

import java.util.*;

class CheckChanges {

private static boolean isDifferent(Properties p1, Properties p2) {

Set> p1EntrySet = p1.entrySet();

Set> p2EntrySet = p2.entrySet();

// Check that the key/value pairs are the same in the entry sets

// obtained from the two Properties.

// If there is an difference, return true.

for (Map.Entry e : p1EntrySet) {

if (!p2EntrySet.contains(e))

return true;

}

for (Map.Entry e : p2EntrySet) {

if (!p1EntrySet.contains(e))

return true;

}

return false;

}

public static void main(String[] s)

{

// System properties prior to modification.

Properties p = (Properties)System.getProperties().clone();

// Modification of system properties.

System.setProperty("dummy.property", "42");

// See if there was modification. The output is "false"

System.out.println(isDifferent(p, System.getProperties()));

}

}

屬性不是線程安全的嗎?

Properties是線程安全的,因此我期望Properties也是這樣,事實(shí)上,Properties類(lèi)的API規(guī)范證實(shí)了這一點(diǎn):

此類(lèi)是線程安全的: 線程可以共享一個(gè)Properties 不需要外部物體 同步。,序列化表格

總結(jié)

以上是生活随笔為你收集整理的java设置属性的取值范围是多少_jvm-Java系统属性的范围的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。