Curriculum design patterns Design patterns succinctly 24-3 intermediary model source code parsing

1 Source resolve

1.1    Source Resolution 1 (JDK regular tasks application call the class )

 

 

 

 

 

1 Source resolve
1.1    Source Resolution 1 (JDK regular tasks application call the class )

The method of a schedule overloaded, Sche last tone method, to be understood that the method sched into a timer in the timing to coordinate the various tasks timerTask taskque. Understood to be a mediator timer, specifically TimerTask is a timing task.

 

 

Timer:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package java.util;

import java.util.concurrent.atomic.AtomicInteger;

public class Timer {
    private final TaskQueue queue;
    private final TimerThread thread;
    private final Object threadReaper;
    private static final AtomicInteger nextSerialNumber = new AtomicInteger(0);

    private static int serialNumber() {
        return nextSerialNumber.getAndIncrement();
    }

    public Timer() {
        this("Timer-" + serialNumber());
    }

    public Timer(boolean var1) {
        this("Timer-" + serialNumber(), var1);
    }

    public Timer(String var1) {
        this.queue = new TaskQueue();
        this.thread = new TimerThread(this.queue);
        this.threadReaper = new Object() {
            protected void finalize() throws Throwable {
                synchronized(Timer.this.queue) {
                    Timer.this.thread.newTasksMayBeScheduled = false;
                    Timer.this.queue.notify();
                }
            }
        };
        this.thread.setName(var1);
        this.thread.start();
    }

    public Timer(String var1, boolean var2) {
        this.queue = new TaskQueue();
        this.thread = new TimerThread(this.queue);
        this.threadReaper = new Object() {
            protected void finalize() throws Throwable {
                synchronized(Timer.this.queue) {
                    Timer.this.thread.newTasksMayBeScheduled = false;
                    Timer.this.queue.notify();
                }
            }
        };
        this.thread.setName(var1);
        this.thread.setDaemon(var2);
        this.thread.start();
    }

    public void schedule(TimerTask var1, long var2) {
        if (var2 < 0L) {
            throw new IllegalArgumentException("Negative delay.");
        } else {
            this.sched(var1, System.currentTimeMillis() + var2, 0L);
        }
    }

    public void schedule(TimerTask var1, Date var2) {
        this.sched(var1, var2.getTime(), 0L);
    }

    public void schedule(TimerTask var1, long var2, long var4) {
        if (var2 < 0L) {
            throw new IllegalArgumentException("Negative delay.");
        } else if (var4 <= 0L) {
            throw new IllegalArgumentException("Non-positive period.");
        } else {
            this.sched(var1, System.currentTimeMillis() + var2, -var4);
        }
    }

    public void schedule(TimerTask var1, Date var2, long var3) {
        if (var3 <= 0L) {
            throw new IllegalArgumentException("Non-positive period.");
        } else {
            this.sched(var1, var2.getTime(), -var3);
        }
    }

    public void scheduleAtFixedRate(TimerTask var1, long var2, long var4) {
        if (var2 < 0L) {
            throw new IllegalArgumentException("Negative delay.");
        } else if (var4 <= 0L) {
            throw new IllegalArgumentException("Non-positive period.");
        } else {
            this.sched(var1, System.currentTimeMillis() + var2, var4);
        }
    }

    public void scheduleAtFixedRate(TimerTask var1, Date var2, long var3) {
        if (var3 <= 0L) {
            throw new IllegalArgumentException("Non-positive period.");
        } else {
            this.sched(var1, var2.getTime(), var3);
        }
    }

    private void sched(TimerTask var1, long var2, long var4) {
        if (var2 < 0L) {
            throw new IllegalArgumentException("Illegal execution time.");
        } else {
            if (Math.abs(var4) > 4611686018427387903L) {
                var4 >>= 1;
            }

            TaskQueue var6 = this.queue;
            synchronized(this.queue) {
                if (!this.thread.newTasksMayBeScheduled) {
                    throw new IllegalStateException("Timer already cancelled.");
                } else {
                    Object var7 = var1.lock;
                    synchronized(var1.lock) {
                        if (var1.state != 0) {
                            throw new IllegalStateException("Task already scheduled or cancelled");
                        }

                        var1.nextExecutionTime = var2;
                        var1.period = var4;
                        var1.state = 1;
                    }

                    this.queue.add(var1);
                    if (this.queue.getMin() == var1) {
                        this.queue.notify();
                    }

                }
            }
        }
    }

    public void cancel() {
        TaskQueue var1 = this.queue;
        synchronized(this.queue) {
            this.thread.newTasksMayBeScheduled = false;
            this.queue.clear();
            this.queue.notify();
        }
    }

    public int purge() {
        int var1 = 0;
        TaskQueue var2 = this.queue;
        synchronized(this.queue) {
            for(int var3 = this.queue.size(); var3 > 0; --var3) {
                if (this.queue.get(var3).state == 3) {
                    this.queue.quickRemove(var3);
                    ++var1;
                }
            }

            if (var1 != 0) {
                this.queue.heapify();
            }

            return var1;
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/1446358788-qq/p/12400199.html
Recommended