I use Tabpane multiple Browser; when I close a tab, I can't dispose the main IPC:
public class JxbrowserDemo extends Application {
@Override
public void start(Stage primaryStage) {
setLevel(Level.ALL);
TabPane tabPane = new TabPane();
tabPane.getTabs().add(createBrowserTab());
tabPane.getTabs().add(createBrowserTab());
StackPane pane = new StackPane();
pane.getChildren().add(tabPane);
Scene scene = new Scene(pane, 500, 400);
primaryStage.setTitle("JxBrowser: JavaFX - Hello World");
primaryStage.setScene(scene);
primaryStage.show();
}
public Tab createBrowserTab() {
Tab tab = new Tab("baidu");
Browser browser = new Browser();
BrowserView browserView = new BrowserView(browser);
tab.setOnClosed(new EventHandler<Event>() {
@Override
public void handle(Event event) {
//last tag close throw exception
//
browser.dispose();
}
});
tab.setContent(browserView);
browser.loadURL("www.google.com");
//tabPane.getTabs().add(tab);
//browserArrayList.add(browser);
return tab;
}
@Override
public void stop() throws Exception {
//dispose here Success
/*browserArrayList.forEach(t->{
t.dispose();
});*/
super.stop();
}
public static void main(String[] args) {
launch(args);
}
}
Log:
02:42:22 信息: Shutting down event queue...
02:42:22 信息: Shutting down event queue... [DONE]
02:42:22 信息: Shutting down event queue...
02:42:22 信息: Shutting down event queue... [DONE]
02:42:22 信息: Channel has been disconnected: SocketChannel{cid=1, bid=1, type=Render}
02:42:22 信息: Channel is disconnected: SocketChannel{cid=1, bid=1, type=Render}
02:42:22 信息: Shutting down event queue...
02:42:22 信息: Shutting down event queue... [DONE]
02:42:22 信息: Shutting down event queue...
02:42:22 信息: Shutting down event queue... [DONE]
02:42:22 信息: IPC connection has been closed. Connection ID: 466160688
02:42:22 信息: Pending IPC connections: 2
02:42:22 信息: Channel has been disconnected: SocketChannel{cid=1, bid=1, type=Browser}
02:42:22 信息: Channel is disconnected: SocketChannel{cid=1, bid=1, type=Browser}
02:42:22 信息: Stopping IPC...
02:42:22 信息: Stopping main channel...
02:42:22 信息: IPC connection has been closed. Connection ID: 466160864
02:42:22 信息: Pending IPC connections: 1
02:42:22 详细: WRITE: ShutdownMessage{type=Shutdown, uid=175, SocketInfo{cid=0, bid=-1, channelType=Main
Hang up here.
About five minutes later it throws the exception:
02:42:22 详细: WRITE: ShutdownMessage{type=Shutdown, uid=175, SocketInfo{cid=0, bid=-1, channelType=Main}
Exception in thread "JavaFX Application Thread" com.teamdev.jxbrowser.chromium.internal.ipc.IPCException: Failed to execute shutdown post message.
02:44:22 信息: Shutting down event queue...
02:44:22 信息: Shutting down event queue... [DONE]
02:44:22 信息: Shutting down event queue...
02:44:22 信息: Shutting down event queue... [DONE]
02:44:22 信息: Channel has been disconnected: SocketChannel{cid=0, bid=-1, type=Main}
02:44:22 信息: IPC connection has been closed. Connection ID: 466161040
02:44:22 信息: Pending IPC connections: 0
02:44:22 信息: Chromium process exit code 0
Try disposing Browser instances in non- JavaFx Application Thread: