1
我正在使用Java創建和編輯Open Office文檔。但是,在修改文檔之後,Java不會退出並仍然運行多個線程,例如Thread [Pipe:CO>],Thread [Pipe:CE>]和Thread [MessageDispatcher]。我希望能夠關閉這些線程,並允許在代碼完成時關閉Java。處理Open Office文檔後如何停止Java
這裏是我的打開和關閉文檔代碼:
private static Object oDesktop;
private static XStorable xStorable;
private static XComponent xSpreadsheetComponent;
private static XComponentContext xContext;
private static XSpreadsheetDocument xSpreadsheetDocument;
private static XSpreadsheets xSpreadsheets;
public static void openDocument(String filename)
{
try
{
// Get the remote office component context
xContext = Bootstrap.bootstrap();
// Get the remote office service manager
XMultiComponentFactory xMCF = xContext.getServiceManager();
// Get the root frame (i.e. desktop) of openoffice framework.
oDesktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
// Desktop has 3 interfaces. The XComponentLoader interface provides ability to load components.
XComponentLoader xCompLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class,
oDesktop);
PropertyValue[] loadProps = new PropertyValue[0];
xSpreadsheetComponent = xCompLoader.loadComponentFromURL(getUpdatedPath(filename), "_blank", 0, loadProps);
xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xSpreadsheetComponent);
xSpreadsheetDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class,
xSpreadsheetComponent);
xSpreadsheets = xSpreadsheetDocument.getSheets();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void closeDocument()
{
try
{
XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, xStorable);
if (xCloseable != null)
{
xCloseable.close(false);
}
else
{
XComponent xComp = (XComponent) UnoRuntime.queryInterface(XComponent.class, xStorable);
xComp.dispose();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
提前感謝!
它是一個獨立的程序嗎? – Rao
我使用Eclipse來運行代碼,如果這是你問的:)。 –
我的意思是,它有一個主要方法嗎? – Rao