quartz-source Understanding the next day

Source: Internet
Author: User

1, quartz source of the bottom, is to use wait, notifyall to deal with. So you have to understand the wait and notify before you know it.

First come to an interview frequently asked Questions: Wait and sleep contrast, for both, in short sleep is thread (thread) static method, thread blocking does not release the acquired lock, waits is the method of object, also block the thread, but also release the lock. A wait thread is awakened with the following scenario: A, another thread calls the object's notify/all;b, wait timeout, C, and calls the interrupted method.

The wait, sleep ratio code is as follows:

public class Waittest implements Runnable {int number = 10; public void FirstMethod () throws Exception {System.out.println ("***first begin**" +thread.currentthread (). GetName (
        ));
            Synchronized (this) {System.out.println ("***first has get lock**");
            Number = 100;
            SYSTEM.OUT.PRINTLN (number);
            Thread.Sleep (50000);
        This.notify (); } public void Secondmethod () throws Exception {System.out.println ("***second begin**" +thread.currentt
        Hread (). GetName ());
            Synchronized (this) {System.out.println ("***second has get lock**");
            /** * (rest 2S, blocking thread) to verify that the current thread object's machine lock is occupied and can access other synchronized code blocks//Thread.Sleep (2000);
            This.wait ();
            Number *= 200;
        System.out.println ("***second end**" + number+ "" +thread.currentthread (). GetName ());
  @Override public void Run () {try {          FirstMethod ();
        catch (Exception e) {e.printstacktrace (); } public static void Main (string[] args) throws Exception {Thread.CurrentThread (). SetName ("Test_wait_thr
        EAD ");
        Waittest threadtest = new Waittest ();
        Thread thread = new Thread (threadtest);
        Thread.Start ();
    Threadtest.secondmethod (); }

}

2, quartz Implementation plan:

The regular thread judges that there are idle threads in the job thread pool and uses the idle thread to perform the job that will be performed (depending on the next execution time and priority two dimensions to determine which job will be executed first).

Missfire the thread to determine whether there is a miss trigger, depending on the set Miss policy, whether to discard or immediately execute the job


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.