Java开放浏览器进程导致30秒延迟
有时我在从Java代码在默认浏览器中打开URL时遇到问题: 基本上Java执行新的进程,但浏览器在30秒后完全打开(看起来浏览器打开过程中有一些超时) 我两个都试过了Java开放浏览器进程导致30秒延迟,java,windows,process,cmd,Java,Windows,Process,Cmd,有时我在从Java代码在默认浏览器中打开URL时遇到问题: 基本上Java执行新的进程,但浏览器在30秒后完全打开(看起来浏览器打开过程中有一些超时) 我两个都试过了 Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler http://google.com"); 及 这两个调用都会等待30秒,然后打开浏览器 我在本文的底部找到了这种方法(通过cmd.exe调用start) 但在打开默认浏览器之前,它会等待同样的30秒 如
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler http://google.com");
及
这两个调用都会等待30秒,然后打开浏览器
我在本文的底部找到了这种方法(通过cmd.exe调用start)
但在打开默认浏览器之前,它会等待同样的30秒
如何让它随时打开?我错过了什么
EDT:延迟只影响从java应用程序调用浏览器的第一次。(按下按钮时从Swing ActionListener调用代码)试试这个-->
正常打开浏览器需要多长时间?它会在1-2秒内打开。我尝试过
Desktop.isDesktopSupported()
它会立即执行并始终返回true。
URI uri = new URI("http://google.com");
Desktop desktop = Desktop.getDesktop().browse(uri);
Runtime.getRuntime().exec("cmd");
PrintWriter stdin = new PrintWriter(p.getOutputStream());
stdin.println("start \"\" \"http://google.com\"");
stdin.close();
int returnCode = p.waitFor();
import java.awt.Desktop;
import java.net.URI;
if(Desktop.isDesktopSupported())
{
Desktop.getDesktop().browse(new URI("http://www.google.com"));
}