5

私たちのアプリケーションは、java.util.prefs.Preferencesクラスを使用して、いくつかのユーザー データ フィールドを格納しています。以下は、設定クラスのコード スニペットです。設定の保存は正常に機能しますが、設定が約 30 秒ごとにディスク アクセスを継続していることに気付きました。Preferences クラスでこれらのバックグラウンド ディスク アクセスを無効にする方法はありますか? (.userRootModeFile.root は約 30 秒ごとに変更されます)

public class NtapPreferences {

private static Preferences prefs = Preferences.userRoot(); //.systemRoot();

/** Prepends "NTAP.<applicationName>." to 'key' for system-wide uniqueness. */
private static String getKeyForApp ( String key ) {
    return "NTAP." + Application.getApplicationName() + "." + key;
}

/**
 * Returns the application preference value for 'key'.<br/>
 * <br/>
 * If 'key' is not a defined preference, then 'def' is returned.
 */
public static String get ( String key, String def ) {
    return prefs.get(getKeyForApp(key), def);
}

/** Sets the application preference value for 'key' as 'value'. */
public static void put ( String key, String value ) {
    //TODO how do we want to resolve failures to put data in the preferences?
    try {
        prefs.put(getKeyForApp(key), value);
        prefs.flush();
    } catch (NullPointerException e) {
        LOG.error(NtapPreferences.class, e);
    } catch (IllegalArgumentException e) {
        LOG.error(NtapPreferences.class, e);
    } catch (IllegalStateException e) {
        LOG.error(NtapPreferences.class, e);
    } catch (BackingStoreException e) {
        LOG.error(NtapPreferences.class, e);
    }
}

/** Removes the application preference value for 'key' if one is defined. */
public static void remove ( String key ) {
    prefs.remove(getKeyForApp(key));
}

}

4

1 に答える 1