مراقبة البرامج الجارية

كيفية مراقبة برنامج جاري

يوضح الكود العيني التالي كيفية مراقبة تشغيل برنامج. يمكن استخدام هذا الكود لمراقبة تشغيل الكود المتعلق بـ Workbook. ببساطة قم باستخدام فئة SystemTimeInterruptMonitor لإنشاء كائن مراقب، استخدم الدالة SetInterruptMonitor لإضافته إلى المعلمات الجاري تشغيلها لـ LoadOptions، ثم استخدم الدالة StartMonitor لتعيين الوقت المتوقع للانقطاع (بالميلي ثانية). إذا تجاوز وقت تشغيل الكود المراقب الوقت المتوقع، سيتم انقطاع البرنامج وسيتم رمي استثناء.

الكود المثالي

SystemTimeInterruptMonitor monitor = new SystemTimeInterruptMonitor(false);
LoadOptions lopts = new LoadOptions();
lopts.setInterruptMonitor(monitor);
monitor.startMonitor(1000); //time limit is 1 second
Workbook wb = new Workbook("Large.xlsx", lopts);
//if the time cost of loading the template file exceeds one second, interruption will be required and exception will be thrown here
//otherwise starts to monitor the save procedure
monitor.startMonitor(1500); //time limit is 1.5 seconds
wb.save("result.xlsx");