OpenOffice配合jodconverter多线程转换文件socket出现异常

package com.jodconvert.socket;

import java.io.File;

import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeManager;

/**
 * 文件转换工具类 主要能将offcie txt类型文件转化成 pdf
 * 
 * @author xzy 2013-6-8下午03:54:50
 * 
 */
public class OpenOfficeTools {


	private static OfficeManager officeManager;

	private static OpenOfficeTools instance = new OpenOfficeTools();


	// 设置任务执行超时时间, 分钟为单位
	// private static final long TASK_EXECUTION_TIMEOUT = 1000 * 60 * 1L *
	private static final long TASK_EXECUTION_TIMEOUT = 1000 * 60 * 1L * 1;

	// 设置任务队列超时时间,分钟为单位
	// private static final long TASK_QUEUE_TIMEOUT = 1000 * 60 * 1L *
	private static final long TASK_QUEUE_TIMEOUT = 1000 * 60 * 1L * 1;

	public static OpenOfficeTools getInstance() {
		return instance;
	}

	public static boolean convert2PDF(File inputFile,File pdfFile) {

		startService();

		OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
		
		try {
				converter.convert(inputFile, pdfFile);

		} catch (Exception e) {
			System.out.println("exception:"+e.getMessage());
		}


		stopService();

		return pdfFile.isFile();
	}

	/**
	 * 启动openoffice服务
	 */
	private static void startService() {
		DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
//		setProcessManager
		try {
			// 设置OpenOffice.org安装目录
			configuration.setOfficeHome("C:\\Program Files (x86)\\OpenOffice.org 3");
			// 设置转换端口,默认为8100
//			configuration.setPortNumbers(new int[] { 8100, 8101, 8102, 8103 });
			configuration.setPortNumbers(8100);
			// 设置任务执行超时时间
			configuration.setTaskExecutionTimeout(TASK_EXECUTION_TIMEOUT);
			// 设置任务队列超时时间 1000 * 60 * 60 * 24L(24h)
			configuration.setTaskQueueTimeout(TASK_QUEUE_TIMEOUT);
			officeManager = configuration.buildOfficeManager();
			officeManager.start(); // 启动服务
		} catch (Exception ce) {
//			log.error(ce.getMessage(), ce);
			ce.printStackTrace();
		}
	}

	/**
	 * 关闭openoffice服务
	 */
	private static void stopService() {
		if (officeManager != null) {
			officeManager.stop();
		}
	}
}

如上所示

用多线程转换时,启动多个,总会有一个转换不成功,而且进程一直会卡在后台,求大神指导!!

你可能感兴趣的:(OpenOffice配合jodconverter多线程转换文件socket出现异常)