/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved.
 * <a>http://www.crunii.com</a>
 */
package com.crunii.micro.common.concurrent;

/**
 * @author 田平 create 2021/12/21 14:11
 */
public class PriorityRunnable implements Runnable, Comparable<PriorityRunnable> {

	/**
	 * 越小优先级越高
	 */
	private int priority;

	private Runnable run;

	public PriorityRunnable(Runnable run, int priority) {
		this.run = run;
		this.priority = priority;
	}

	public int getPriority() {
		return priority;
	}

	@Override
	public int compareTo(PriorityRunnable o) {
		return Integer.compare(priority, o.getPriority());
	}

	@Override
	public void run() {
		run.run();
	}
}
