実行中のプログラムの監視

実行中のプログラムの監視方法

以下のサンプルコードは実行中のプログラムを監視する方法を示しています。このコードは、Workbook関連のコードを監視するために使用できます。単にSystemTimeInterruptMonitorクラスを使用して監視オブジェクトを作成し、LoadOptionsの実行パラメータに追加するためにSetInterruptMonitor関数を使用し、それから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");