设置保存超时
Contents
[
Hide
]设置保存超时
Aspose.CAD for Java API 允许您在保存时设置超时。这在保存过程需要很多时间或占用大量内存的情况下可能会很有用。为此,API提供了 InterruptionTokenSource 类。InterruptionTokenSource 类提供了一个用于中断长时间操作的令牌。
示例代码
以下代码片段演示了 InterruptionTokenSource 类的使用。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java | |
final String SourceDir = Utils.getDataDir_DWGDrawings(); | |
final String OutputDir = Utils.getDataDir_Output(); | |
final InterruptionTokenSource source = new com.aspose.cad.InterruptionTokenSource(); | |
try { | |
final CadImage cadImageBig = (CadImage)Image.load(SourceDir + "Drawing11.dwg"); | |
try { | |
CadRasterizationOptions rasterizationOptionsBig = new CadRasterizationOptions(); | |
rasterizationOptionsBig.setPageWidth(cadImageBig.getSize().getWidth() / 2); | |
rasterizationOptionsBig.setPageHeight(cadImageBig.getSize().getHeight() / 2); | |
final PdfOptions CADfBig = new PdfOptions(); | |
CADfBig.setVectorRasterizationOptions(rasterizationOptionsBig); | |
CADfBig.setInterruptionToken(source.getToken()); | |
java.lang.Thread thread = new java.lang.Thread(new Runnable() { | |
@Override | |
public void run() { | |
try { | |
cadImageBig.save(OutputDir + "PutTimeoutOnSave_out.pdf", CADfBig); | |
} catch (Throwable th) { | |
System.out.println("interrupted !!!"); | |
} | |
} | |
}); | |
thread.start(); | |
TimeUnit.SECONDS.sleep(3); | |
source.interrupt(); | |
thread.join(); | |
} finally { | |
cadImageBig.dispose(); | |
} | |
} finally { | |
source.dispose(); | |
} |