RFR: 8342453: Remove calls to doPrivileged in javafx.graphics/com.sun.javafx.tk [v2]

Kevin Rushforth kcr at openjdk.org
Wed Oct 30 20:43:09 UTC 2024


On Tue, 29 Oct 2024 22:46:30 GMT, Kevin Rushforth <kcr at openjdk.org> wrote:

>> modules/javafx.graphics/src/main/java/com/sun/javafx/tk/quantum/QuantumToolkit.java line 142:
>> 
>>> 140: 
>>> 141:     private static final boolean multithreaded = initMultithreaded();
>>> 142:     private static boolean initMultithreaded() {
>> 
>> Have you considered a pattern such as this?
>> 
>> 
>>     private static final boolean multithreaded = ((Supplier<Boolean>)() -> {
>>         // If it is not specified, or it is true, then it should
>>         // be true. Otherwise it should be false.
>>         String value = System.getProperty("quantum.multithreaded");
>>         if (value == null) return true;
>>         final boolean result = Boolean.parseBoolean(value);
>>         if (verbose) {
>>             System.out.println(result ? "Multi-Threading Enabled" : "Multi-Threading Disabled");
>>         }
>>         return result;
>>     }).get();
>> 
>> 
>> This would prevent a proliferation of many new init methods.
>
> That's an interesting suggestion: trading a new method for a lambda (the prior code used a lambda to pass to the doPrivileged, so it's also less of a delta). I'll take a look at it and see if it looks better to me.

I decided to make this change. Thanks for the suggestion.

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/1608#discussion_r1823362381


More information about the openjfx-dev mailing list