Java 在 Microsoft Server 上为每个用户编写一个进程
Java program one process per user on Microsoft Server
我收到要修复的错误。有人编写了从其他应用程序调用打印文档的程序。带有此程序的 Jar 在 Microsoft 服务器上供少数用户使用。问题是当其中一个用户同时想要打印和其他用户时。 Fox 示例 user1 单击打印并进行打印预览,同时 user2 执行相同的操作但他没有打印预览,因为文档 user2 的打印预览显示在屏幕 user1 上。我不知道错误在哪里。也许主应用程序调用相同的 jar 实例或使用相同的进程。这是我的方法代码,当用户单击打印时调用它。
public void openCreatedFile() {
String filePath = "file:///" + findNewlyCreatedFile().replace("\", "/");
try {
if (xContext != null)
System.out.println("Opening file ...");
xMCF = xContext.getServiceManager();
Object oDesktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
xCLoader = UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class, oDesktop);
com.sun.star.beans.PropertyValue[] szEmptyArgs = new com.sun.star.beans.PropertyValue[0];
xComp = xCLoader.loadComponentFromURL(filePath, "_blank", 0, szEmptyArgs);
System.out.println(filePath);
xDoc = UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class, xComp);
xContext = null;
} catch (Exception e) {
e.printStackTrace(System.err);
Thread.currentThread();
}
}
您必须更改您的 BootstrapSocketConnector。这是解决方案:
for(int i = 8100; i<=65535 ; i++){
if(available(i)){
libre.xContext = BootstrapSocketConnector.bootstrap(libre.oooExeFolder, "localhost", i);
System.out.println(i);
break;
}
}
例如8100,这里必须使用你正在使用的端口来连接。
例如方法 available()
,您可以在其中检查最近的可用端口:
private static boolean available(int port) {
try{
Socket ignored = new Socket("localhost", port);
return false;
} catch (IOException ignored) {
return true;
}
}
我收到要修复的错误。有人编写了从其他应用程序调用打印文档的程序。带有此程序的 Jar 在 Microsoft 服务器上供少数用户使用。问题是当其中一个用户同时想要打印和其他用户时。 Fox 示例 user1 单击打印并进行打印预览,同时 user2 执行相同的操作但他没有打印预览,因为文档 user2 的打印预览显示在屏幕 user1 上。我不知道错误在哪里。也许主应用程序调用相同的 jar 实例或使用相同的进程。这是我的方法代码,当用户单击打印时调用它。
public void openCreatedFile() {
String filePath = "file:///" + findNewlyCreatedFile().replace("\", "/");
try {
if (xContext != null)
System.out.println("Opening file ...");
xMCF = xContext.getServiceManager();
Object oDesktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
xCLoader = UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class, oDesktop);
com.sun.star.beans.PropertyValue[] szEmptyArgs = new com.sun.star.beans.PropertyValue[0];
xComp = xCLoader.loadComponentFromURL(filePath, "_blank", 0, szEmptyArgs);
System.out.println(filePath);
xDoc = UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class, xComp);
xContext = null;
} catch (Exception e) {
e.printStackTrace(System.err);
Thread.currentThread();
}
}
您必须更改您的 BootstrapSocketConnector。这是解决方案:
for(int i = 8100; i<=65535 ; i++){
if(available(i)){
libre.xContext = BootstrapSocketConnector.bootstrap(libre.oooExeFolder, "localhost", i);
System.out.println(i);
break;
}
}
例如8100,这里必须使用你正在使用的端口来连接。
例如方法 available()
,您可以在其中检查最近的可用端口:
private static boolean available(int port) {
try{
Socket ignored = new Socket("localhost", port);
return false;
} catch (IOException ignored) {
return true;
}
}