הגדרה של זמן קצוב בעת שמירה
Contents
[
Hide
]הגדרה של זמן קצוב בעת שמירה
Aspose.CAD עבור 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(); | |
} |