ADDITIONAL SYSTEM INFORMATION :
openjdk version "19-ea" 2022-09-20
OpenJDK Runtime Environment (build 19-ea+34-2229)
OpenJDK 64-Bit Server VM (build 19-ea+34-2229, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
In swing or javafx, the update of the control needs to be done in the specified thread. Currently, there is no way to set the Executor in the way of creating VirtualThread (or I missed it), so I hope to provide an override function for setting the Executor. Thread#startVirtualThread(Executor, Runnable), currently I can only use reflection for testing
//swing scheduler
class SwingExecutor implements Executor{
@Override
public void execute(Runnable command) {
EventQueue.invokeLater(command);
}
}
//create Virtual Thread
static Thread newVirtualThread(Executor scheduler, Runnable task){
try {
Class<?> threadBuilders = Class.forName("java.lang.ThreadBuilders");
Method method = threadBuilders.getDeclaredMethod("newVirtualThread",
Executor.class, String.class,
int.class, Runnable.class);
method.setAccessible(true);
return (Thread) method.invoke(null, scheduler, null, 0, task);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
openjdk version "19-ea" 2022-09-20
OpenJDK Runtime Environment (build 19-ea+34-2229)
OpenJDK 64-Bit Server VM (build 19-ea+34-2229, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
In swing or javafx, the update of the control needs to be done in the specified thread. Currently, there is no way to set the Executor in the way of creating VirtualThread (or I missed it), so I hope to provide an override function for setting the Executor. Thread#startVirtualThread(Executor, Runnable), currently I can only use reflection for testing
//swing scheduler
class SwingExecutor implements Executor{
@Override
public void execute(Runnable command) {
EventQueue.invokeLater(command);
}
}
//create Virtual Thread
static Thread newVirtualThread(Executor scheduler, Runnable task){
try {
Class<?> threadBuilders = Class.forName("java.lang.ThreadBuilders");
Method method = threadBuilders.getDeclaredMethod("newVirtualThread",
Executor.class, String.class,
int.class, Runnable.class);
method.setAccessible(true);
return (Thread) method.invoke(null, scheduler, null, 0, task);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
- relates to
-
JDK-8253546 Explore using AWT EventQueue dispatch thread as carrier thread
-
- In Progress
-