简体   繁体   English

分析期间无法访问菜单

[英]Menu not accessible during profiling

I have a JavaFX application which I want to run under the JVisualVM profiler. 我有一个JavaFX应用程序,我想在JVisualVM分析器下运行。 However, I cannot access the menu items from the menu bar when running it under the profiler. 但是,在分析器下运行时,我无法从菜单栏访问菜单项。

So far, my application is just a simple scene built with SceneBuilder. 到目前为止,我的应用程序只是一个使用SceneBuilder构建的简单场景。 It has an AnchorPane and a default Menubar. 它有一个AnchorPane和一个默认的菜单栏。

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <MenuBar layoutX="-41.0" layoutY="-12.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
        <menus>
          <Menu mnemonicParsing="false" text="File">
            <items>
              <MenuItem mnemonicParsing="false" text="Close" />
            </items>
          </Menu>
        </menus>
      </MenuBar>
   </children>
</AnchorPane>

The code is also straight-forward, nothing special: 代码也是直截了当的,没什么特别的:

@Override
public void start(Stage primaryStage) throws IOException
{
    String path = "Window.fxml";
    URL url = getClass().getClassLoader().getResource(path);
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(url);

    Parent root = loader.load();        
    Scene scene = new Scene(root, 600, 400);
    primaryStage.setScene(scene);
    primaryStage.show();
}

I do the following: 我做以下事情:

  • run the application from Eclipse until the window shows up, 从Eclipse运行应用程序,直到窗口出现,
  • click on "File" to see whether "Close" becomes visible 单击“文件”以查看“关闭”是否可见
  • start JVisualVM, 启动JVisualVM,
  • double click my application, 双击我的申请,
  • go to the "Profiler" tab 转到“Profiler”选项卡
  • click "CPU" and wait until it has injected profiling instructions 单击“CPU”并等待它已注入分析说明
  • click on "File" again, but "Close" does not appear 再次单击“文件”,但不会出现“关闭”

In Eclipse I see the following error messages coming up in the Console window very fast: 在Eclipse中,我看到控制台窗口中出现的以下错误消息非常快:

Exception in thread "JavaFX Application Thread" java.lang.NoClassDefFoundError: com/sun/javafx/tk/Toolkit$$Lambda$166
    at com.sun.javafx.tk.Toolkit$$Lambda$166/563347763.get$Lambda(Unknown Source)
    at com.sun.javafx.tk.Toolkit.runPulse(Unknown Source)
    at com.sun.javafx.tk.Toolkit.firePulse(Unknown Source)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
    at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$363(Unknown Source)
    at com.sun.javafx.tk.quantum.QuantumToolkit$$Lambda$41/353428524.run(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
    at com.sun.glass.ui.win.WinApplication$$Lambda$37/1109371569.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

How can I profile a method that gets called from a menu of my JavaFX application? 如何分析从我的JavaFX应用程序菜单中调用的方法?

I have also tried packaging the application into an executable JAR file, so that Eclipse is not involved. 我还尝试将应用程序打包到可执行的JAR文件中,以便不涉及Eclipse。

If the profiler uses BCI/instrumentation, then this problem might be relevant: Transforming lambdas in Java 8 如果探查器使用BCI /检测,那么这个问题可能是相关的: 在Java 8中转换lambdas

Should the profiler have any option(s) to stop tracing performance of lambdas, try using it. 如果探查器有任何选项可以停止跟踪lambdas的性能,请尝试使用它。

It would be interesting to know whether your problem still persists with newer versions of Java. 了解您的问题是否仍然存在于较新版本的Java中将会很有趣。

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

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