简体   繁体   English

如何将数据传递给 Platform.runLater

[英]How to pass data to Platform.runLater

I need to change the title of my GUI window based on the socket data received in the socket receiver thread.我需要根据在套接字接收器线程中接收到的套接字数据更改我的 GUI window 的标题。 I want to know is there a way to pass variables like int , long etc. to Platform.runLater , in order to avoid mutex locks just for accessing an int variable.我想知道有没有办法将intlong等变量传递给Platform.runLater ,以避免仅用于访问int变量的互斥锁。 This is a sample code:这是一个示例代码:

// Receiver Socket thread
int opnMode = byteBuffer.getInt();

Platform.runLater(() -> { //GUI thread
    ((Stage) Fx.Pane.getScene().getWindow()).setTitle("Operation mode " + " (" + opnMode + ")");
});

In the above code I'm using the variable opnMode without using mutex as it is being accessed by two threads.在上面的代码中,我使用变量opnMode而不使用互斥锁,因为它被两个线程访问。

Your code should work just fine as it is because your int is effectively final.您的代码应该可以正常工作,因为您的 int 实际上是最终的。 Here is a discussion of this issue: https://www.baeldung.com/java-effectively-final这是对这个问题的讨论: https://www.baeldung.com/java-effectively-final

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM