Đặt thời gian chờ khi lưu
Đặt thời gian chờ khi lưu
Aspose.CAD cho Java API cho phép bạn đặt một thời gian chờ khi lưu. Điều này có thể hữu ích trong các trường hợp quá trình lưu tốn nhiều thời gian hoặc tiêu tốn nhiều bộ nhớ. Để làm điều này, API cung cấp lớp InterruptionTokenSource. Lớp InterruptionTokenSource cung cấp một mã thông báo được sử dụng để ngắt các hoạt động dài.
Mẫu mã
Đoạn mã sau đây minh họa việc sử dụng lớp InterruptionTokenSource.
// 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(); | |
} |