저장 시 타임아웃 설정
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(); | |
} |