ThreadInterruptMonitor

Inheritance: java.lang.Object, com.aspose.cells.AbstractInterruptMonitor

public class ThreadInterruptMonitor extends AbstractInterruptMonitor

Simple implementation of AbstractInterruptMonitor by starting another thread to require the interruption after sleeping user specified limit.

Remarks

One monitor instance can be used repeatedly, as long as you monitor each process in sequence. It should not be used to monitor multiple procedures concurrently in multi-threads.

Example

The following example shows how to monitor the load and save procedure with specified time limit:

         ThreadInterruptMonitor monitor = new ThreadInterruptMonitor(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 finishes the monitor thread and starts to monitor the save procedure
         monitor.finishMonitor();
         monitor.startMonitor(1500); //time limit is 1.5 seconds
         wb.save("result.xlsx");
         monitor.finishMonitor();

Constructors

ConstructorDescription
ThreadInterruptMonitor(boolean terminateWithoutException)Constructs one interruption monitor.

Methods

MethodDescription
equals(Object arg0)
finishMonitor()Finishes the monitor for one procedure.
getClass()
getTerminateWithoutException()See AbstractInterruptMonitor.getTerminateWithoutException().
hashCode()
isInterruptionRequested()This implementation just checks whether the time cost(from the time when starting this monitor to now) is greater than user specified limit.
notify()
notifyAll()
startMonitor(int msLimit)Starts the monitor with the specified time limit.
toString()
wait()
wait(long arg0)
wait(long arg0, int arg1)

ThreadInterruptMonitor(boolean terminateWithoutException)

public ThreadInterruptMonitor(boolean terminateWithoutException)

Constructs one interruption monitor.

Parameters:

ParameterTypeDescription
terminateWithoutExceptionbooleanAbstractInterruptMonitor.getTerminateWithoutException()

equals(Object arg0)

public boolean equals(Object arg0)

Parameters:

ParameterTypeDescription
arg0java.lang.Object

Returns: boolean

finishMonitor()

public void finishMonitor()

Finishes the monitor for one procedure.

Remarks

Calling this method after the monitored procedure can release the monitor thread earlier, especially when there is no interruption for it(the time cost of that procedure is less than the specified time limit).

getClass()

public final native Class<?> getClass()

Returns: java.lang.Class

getTerminateWithoutException()

public boolean getTerminateWithoutException()

See AbstractInterruptMonitor.getTerminateWithoutException(). This property is specified by user when constructing this monitor instance.

Returns: boolean

hashCode()

public native int hashCode()

Returns: int

isInterruptionRequested()

public boolean isInterruptionRequested()

This implementation just checks whether the time cost(from the time when starting this monitor to now) is greater than user specified limit.

Returns: boolean

notify()

public final native void notify()

notifyAll()

public final native void notifyAll()

startMonitor(int msLimit)

public void startMonitor(int msLimit)

Starts the monitor with the specified time limit. The start time to calculate time cost is just when this method is called, so the procedure which needs to be monitored should be started just after this call.

Parameters:

ParameterTypeDescription
msLimitinttime limit(ms) to require the interruption.

toString()

public String toString()

Returns: java.lang.String

wait()

public final void wait()

wait(long arg0)

public final native void wait(long arg0)

Parameters:

ParameterTypeDescription
arg0long

wait(long arg0, int arg1)

public final void wait(long arg0, int arg1)

Parameters:

ParameterTypeDescription
arg0long
arg1int