How to close jcef_helper.exe while App is still alive.

Having problems with building or using the JCEF Java binding? Ask your questions here.

How to close jcef_helper.exe while App is still alive.

Postby pe1liu » Thu Aug 20, 2020 8:07 am

Hello JCEFers,

I have a JavaFx GUI that should be able to show 3D plotly figures. Because the webview of JavaFx doesn't support webgl and therefore can't load plotly 3D plots. So I found JCEF and applyed it to my App.

Here ist the problem:
The following code is to create the gui and display figures using a button.
Code: Select all
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class TestCefWebView extends Application {

  private VBox plots = new VBox();

  @Override
  public void start(Stage primaryStage) throws Exception {

    plots.setPadding(new Insets(10));
    plots.setSpacing(10);

    Button button1 = new Button("Show next plot");
    button1.setOnAction(e -> showNextPlot());

    plots.getChildren().add(button1);

    // Create and define scroll pane to show the plots
    ScrollPane scrollPane = new ScrollPane();
    scrollPane.setContent(plots);
    scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
    Scene scene = new Scene(scrollPane, 1200, 800);
    primaryStage.setTitle("Plots Test");
    primaryStage.setScene(scene);
    primaryStage.show();
  }


  private void showNextPlot() {
    // Delete the old figure
    plots.getChildren().removeIf(e -> e instanceof SwingNode);

    // Load the new figure
    CefWebview cefWebview = CefWebview.getInstance();
    plots.getChildren().add(cefWebview.load("http://localhost:8090/view/plotlyfigure.html")); // only an example, in reality the url of figure will be changed.
  }


  public static void main(String[] args) {
    launch(args);
    System.exit(0);
  }
}

Here the CefWebview class:
Code: Select all
import com.jogamp.opengl.awt.GLJPanel;
import javafx.embed.swing.SwingNode;
import javafx.scene.layout.AnchorPane;
import org.cef.CefApp;
import org.cef.CefClient;
import org.cef.browser.CefBrowser;


public class CefWebview {
  private final CefApp app;
  private final CefClient client;
  private CefBrowser browser;
  private static CefWebview instance;

  private CefWebview() {
    this.app = CefApp.getInstance();
    this.client = app.createClient();
  }

  public static CefWebview getInstance() {
    if (CefWebview.instance == null) {
      CefWebview.instance = new CefWebview();
    }
    return CefWebview.instance;
  }

  public SwingNode load(String url) {
    SwingNode swingNode = new SwingNode();
    browser = client.createBrowser(url, true, false);
    GLJPanel browserUi = (GLJPanel) browser.getUIComponent();
    AnchorPane.setTopAnchor(swingNode, 0d);
    AnchorPane.setBottomAnchor(swingNode, 0d);
    AnchorPane.setRightAnchor(swingNode, 0d);
    AnchorPane.setLeftAnchor(swingNode, 0d);
    swingNode.setContent(browserUi);

    return swingNode;
  }
}


When I click the button to show next figure, I want to delete the first page and then show the new page.

But when the old page is deleted, the corresponding jcef_helper.exe process still runs(can be checked in Windows Task Manager). Every time I click the button, a new jcef_helper.exe will be created. That means jcef_helper.exe accumulates. In this way, when the user clicks the button 100 times there will be more than 100 jcef_helper.exe running. That harms on the performance and also takes up much CPU resources.
All of the jcef_helper.exe are killed only if the App is closed.

I've tried client.dispose(), but it birngs no effect.

So is there any way to kill the old jcef_help.exe while App is still alive?

Many thanks!
pe1liu
Newbie
 
Posts: 9
Joined: Thu Aug 20, 2020 7:17 am

Re: How to close jcef_helper.exe while App is still alive.

Postby magreenblatt » Thu Aug 20, 2020 10:44 am

What OS and CEF version?

When I click the button to show next figure, I want to delete the first page and then show the new page.

What do you mean by "page"? Are you creating a new CefBrowser every time, or re-using the same CefBrowser?
magreenblatt
Site Admin
 
Posts: 10922
Joined: Fri May 29, 2009 6:57 pm

Re: How to close jcef_helper.exe while App is still alive.

Postby pe1liu » Fri Aug 21, 2020 1:31 am

Hi, thanks for answering.

I'm using win7 64 bits.
JCEF Version = 84.3.8.261
CEF Version = 84.3.8
Chromium Version = 84.0.4147.105

"page" means figure or plot.
Yeah, I create a new CefBrowser each time when I display a new figure.

(Because the example is simplified. Actually each time more than one figure will be shown in the GUI).
pe1liu
Newbie
 
Posts: 9
Joined: Thu Aug 20, 2020 7:17 am

Re: How to close jcef_helper.exe while App is still alive.

Postby magreenblatt » Fri Aug 21, 2020 10:20 am

If you’re displaying new figures frequently I suggest you reuse the same CefBrowser (just hide it when not in use).
magreenblatt
Site Admin
 
Posts: 10922
Joined: Fri May 29, 2009 6:57 pm

Re: How to close jcef_helper.exe while App is still alive.

Postby pe1liu » Mon Aug 24, 2020 1:47 am

Yes, that would be a solution. I'll try it. Thank you.

But the performance will still be effected by the potential maximum of figures.
For example, one time 50 figures will be displayed, then 50 CefBrowser will be created. Next several times, only 10 figures will be shown. In this way only 10 of the created 50 CefBrowser will be used effectively. So while the period of time (before next time with 50 figures again), the rest 40 CegBrowser will run in the background, wait and do nothing.

So is there a solution to keep the number of Cebrowser always equal to the actual needed?
pe1liu
Newbie
 
Posts: 9
Joined: Thu Aug 20, 2020 7:17 am

Re: How to close jcef_helper.exe while App is still alive.

Postby magreenblatt » Mon Aug 24, 2020 9:11 am

Please explain your use case in greater detail. Why is it necessary to show each figure in a separate browser versus showing all figures in the same browser?
magreenblatt
Site Admin
 
Posts: 10922
Joined: Fri May 29, 2009 6:57 pm

Re: How to close jcef_helper.exe while App is still alive.

Postby pe1liu » Mon Aug 24, 2020 9:38 am

Sure.

(Actually I've considered your proposal already. It's very costly to do so at the plotly side, therefore I asked for ideas at the side of JCEF in forum.)

I create 3D Plotly figures like this. https://plotly.com/javascript/3d-surface-plots/#multiple-3d-surface-plots
Each figure is a html file in fact. So it can be loaded by CefBrowser.
If all htmls are merged to one single html when user creates multiple figures, the control of each figure will be difficult.
Because each figure may be updated later (like data update, layout update etc.). And user would also like to select some figures and export as svg.

Yes, this way works theoretically and technically. So if there is no solution at the side of JCEF, I'll think over, how to make it work with merged html.

Thanks for helping :)
pe1liu
Newbie
 
Posts: 9
Joined: Thu Aug 20, 2020 7:17 am

Re: How to close jcef_helper.exe while App is still alive.

Postby magreenblatt » Mon Aug 24, 2020 9:55 am

I would suggest making it a JavaScript app that runs in a single CefBrowser. Creating many CefBrowsers will be much less efficient.
magreenblatt
Site Admin
 
Posts: 10922
Joined: Fri May 29, 2009 6:57 pm

Re: How to close jcef_helper.exe while App is still alive.

Postby pe1liu » Tue Aug 25, 2020 1:57 am

Thast means there is no way to close or dispose specific CefBrowser?

ok, then I'll solve it by developing a small javascript app. Thanks for your suggestion.
pe1liu
Newbie
 
Posts: 9
Joined: Thu Aug 20, 2020 7:17 am

Re: How to close jcef_helper.exe while App is still alive.

Postby pe1liu » Wed Sep 23, 2020 9:29 am

magreenblatt wrote:I would suggest making it a JavaScript app that runs in a single CefBrowser. Creating many CefBrowsers will be much less efficient.


Hi, I did it and created only one CefBrowser to hold all of the html plots. But not as expected, the jcef_helper.exe still takes as many memorys as before (each plot owns a browser). I thought the performance would be better if I create only one CefBrowser.

Is there any other ideas to improve the performance? Because my tool only takes 200 MB RAM after started. But the jcef_helper.exe takes more than 1 GB RAM.

For any suggestion I would be grateful.
Thanks!
pe1liu
Newbie
 
Posts: 9
Joined: Thu Aug 20, 2020 7:17 am

Next

Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 5 guests