InterruptMonitor

Inheritance: java.lang.Object

All Implemented Interfaces: com.aspose.imaging.multithreading.IInterruptMonitor

public class InterruptMonitor implements IInterruptMonitor

يمثل معلومات حول الانقطاع.

المنشئات

المنشئالوصف
InterruptMonitor()ينشئ مثيلاً جديدًا من الفئة InterruptMonitor.

الطرق

طريقةالوصف
getThreadLocalInstance()يحصل على مثيل IInterruptMonitor الفريد لكل خيط.
setThreadLocalInstance(IInterruptMonitor value)يضبط مثيل IInterruptMonitor الفريد لكل خيط.
isThreadInterrupted()يعيد true إذا كان مراقب المقاطعة للخيط الحالي موجودًا وتم مقاطعته، وإلا يعيد false.
removeAllMonitors()يزيل جميع مراقبي الخيوط، بما في ذلك تلك الخاصة بالخيوط الحية.
isInterrupted()يحصل على القيمة التي تشير إلى ما إذا كان يجب مقاطعة العمليات.
interrupt()يرسل طلبًا لمقاطعة العمليات.

Example: The following example shows how to interrupt the long process of image conversion.

/**
 * <p>This is helper class which initiates image conversion and waits for its interruption.</p>
 */
class Worker implements Runnable {
    /**
     * The path to the input image.
     */
    private final String inputPath;

    /**
     * The path to the output image.
     */
    private final String outputPath;

    /**
     * The save options.
     */
    private final com.aspose.imaging.ImageOptionsBase saveOptions;

    /**
     * The interrupt monitor.
     */
    private final com.aspose.imaging.multithreading.InterruptMonitor monitor;

    /**
     * <p>Initializes a new instance of the {#link #Worker} class.</p>
     *
     * @param inputPath   The path to the input image.
     * @param outputPath  The path to the output image.
     * @param saveOptions The save options.
     * @param monitor     The interrupt monitor.
     */
    public Worker(String inputPath, String outputPath, com.aspose.imaging.ImageOptionsBase saveOptions, com.aspose.imaging.multithreading.InterruptMonitor monitor) {
        this.inputPath = inputPath;
        this.outputPath = outputPath;
        this.saveOptions = saveOptions;
        this.monitor = monitor;
    }

    /**
     * <p>Converts an image from one format to another. Handles interruption.</p>
     */
    public void run() {
        try {
            com.aspose.imaging.Image image = com.aspose.imaging.Image.load(this.inputPath);

            // تعيين مثيل محلي للخيط من مراقب المقاطعة.
            com.aspose.imaging.multithreading.InterruptMonitor.setThreadLocalInstance(this.monitor);

            try {
                image.save(this.outputPath, this.saveOptions);
            } catch (com.aspose.imaging.coreexceptions.OperationInterruptedException e) {
                System.out.printf(
                        "The worker thread #%s has been interrupted at %s\r\n",
                        java.lang.Thread.currentThread().getId(),
                        new java.util.Date());
            } finally {
                image.dispose();

                // إعادة تعيين المثيل المحلي للخيط من مراقب المقاطعة.
                com.aspose.imaging.multithreading.InterruptMonitor.setThreadLocalInstance(null);
            }
        } catch (java.lang.Exception e) {
            // اطبع معلومات مفصلة عن أي استثناء غير متوقع.
            System.out.println(e);
        }
    }
}

// فيما يلي المثال الرئيسي باستخدام الفئة Worker.
String baseDir = "c:\\temp\\";

com.aspose.imaging.multithreading.InterruptMonitor monitor = new com.aspose.imaging.multithreading.InterruptMonitor();
Worker worker = new Worker(baseDir + "big.png", baseDir + "big.bmp", new com.aspose.imaging.imageoptions.BmpOptions(), monitor);

// ابدأ العامل في خيط مخصص.
Thread thread = new Thread(worker);
thread.start();

try {
    // قم ببعض العمل المفيد هنا.
    Thread.sleep(2000);

    // طلب مقاطعة خيط العامل.
    monitor.interrupt();
    System.out.printf("Interrupting the worker thread #%s at %s", thread.getId(), new java.util.Date());

    // انتظر المقاطعة.
    thread.join();
} catch (InterruptedException e) {
    System.out.println(e);
}

System.out.println("Done. Press ENTER to exit.");
System.in.read();

// قد يبدو الإخراج هكذا:
// مقاطعة خيط العامل #11 في Tue Aug 06 17:57:52 YEKT 2019
// تم مقاطعة خيط العامل #11 في Tue Aug 06 17:57:59 YEKT 2019
// تم. اضغط ENTER للخروج.

InterruptMonitor()

public InterruptMonitor()

ينشئ مثيلاً جديدًا من الفئة InterruptMonitor.

getThreadLocalInstance()

public static IInterruptMonitor getThreadLocalInstance()

يحصل على مثيل IInterruptMonitor الفريد لكل خيط.

Returns: IInterruptMonitor

setThreadLocalInstance(IInterruptMonitor value)

public static void setThreadLocalInstance(IInterruptMonitor value)

يضبط مثيل IInterruptMonitor الفريد لكل خيط.

Parameters:

معاملنوعالوصف
valueIInterruptMonitor

isThreadInterrupted()

public static boolean isThreadInterrupted()

يعيد true إذا كان مراقب المقاطعة للخيط الحالي موجودًا وتم مقاطعته، وإلا يعيد false.

Returns: منطقي - true إذا كان مراقب المقاطعة للخيط الحالي موجودًا، وتم مقاطعته وإلا false.

removeAllMonitors()

public static void removeAllMonitors()

يزيل جميع مراقبي الخيوط، بما في ذلك تلك الخاصة بالخيوط الحية.

isInterrupted()

public boolean isInterrupted()

يحصل على القيمة التي تشير إلى ما إذا كان يجب مقاطعة العمليات.

Returns: boolean

interrupt()

public void interrupt()

يرسل طلبًا لمقاطعة العمليات.

Example: The following example shows how to interrupt the long process of image conversion.

/**
 * <p>This is helper class which initiates image conversion and waits for its interruption.</p>
 */
class Worker implements Runnable {
    /**
     * The path to the input image.
     */
    private final String inputPath;

    /**
     * The path to the output image.
     */
    private final String outputPath;

    /**
     * The save options.
     */
    private final com.aspose.imaging.ImageOptionsBase saveOptions;

    /**
     * The interrupt monitor.
     */
    private final com.aspose.imaging.multithreading.InterruptMonitor monitor;

    /**
     * <p>Initializes a new instance of the {#link #Worker} class.</p>
     *
     * @param inputPath   The path to the input image.
     * @param outputPath  The path to the output image.
     * @param saveOptions The save options.
     * @param monitor     The interrupt monitor.
     */
    public Worker(String inputPath, String outputPath, com.aspose.imaging.ImageOptionsBase saveOptions, com.aspose.imaging.multithreading.InterruptMonitor monitor) {
        this.inputPath = inputPath;
        this.outputPath = outputPath;
        this.saveOptions = saveOptions;
        this.monitor = monitor;
    }

    /**
     * <p>Converts an image from one format to another. Handles interruption.</p>
     */
    public void run() {
        try {
            com.aspose.imaging.Image image = com.aspose.imaging.Image.load(this.inputPath);

            // تعيين مثيل محلي للخيط من مراقب المقاطعة.
            com.aspose.imaging.multithreading.InterruptMonitor.setThreadLocalInstance(this.monitor);

            try {
                image.save(this.outputPath, this.saveOptions);
            } catch (com.aspose.imaging.coreexceptions.OperationInterruptedException e) {
                System.out.printf(
                        "The worker thread #%s has been interrupted at %s\r\n",
                        java.lang.Thread.currentThread().getId(),
                        new java.util.Date());
            } finally {
                image.dispose();

                // إعادة تعيين المثيل المحلي للخيط من مراقب المقاطعة.
                com.aspose.imaging.multithreading.InterruptMonitor.setThreadLocalInstance(null);
            }
        } catch (java.lang.Exception e) {
            // اطبع معلومات مفصلة عن أي استثناء غير متوقع.
            System.out.println(e);
        }
    }
}

// فيما يلي المثال الرئيسي باستخدام الفئة Worker.
String baseDir = "c:\\temp\\";

com.aspose.imaging.multithreading.InterruptMonitor monitor = new com.aspose.imaging.multithreading.InterruptMonitor();
Worker worker = new Worker(baseDir + "big.png", baseDir + "big.bmp", new com.aspose.imaging.imageoptions.BmpOptions(), monitor);

// ابدأ العامل في خيط مخصص.
Thread thread = new Thread(worker);
thread.start();

try {
    // قم ببعض العمل المفيد هنا.
    Thread.sleep(2000);

    // طلب مقاطعة خيط العامل.
    monitor.interrupt();
    System.out.printf("Interrupting the worker thread #%s at %s", thread.getId(), new java.util.Date());

    // انتظر المقاطعة.
    thread.join();
} catch (InterruptedException e) {
    System.out.println(e);
}

System.out.println("Done. Press ENTER to exit.");
System.in.read();

// قد يبدو الإخراج هكذا:
// مقاطعة خيط العامل #11 في Tue Aug 06 17:57:52 YEKT 2019
// تم مقاطعة خيط العامل #11 في Tue Aug 06 17:57:59 YEKT 2019
// تم. اضغط ENTER للخروج.