Annotation Interface Priority


@Target(METHOD) @Retention(RUNTIME) public @interface Priority
Priority Annotation 优先级注解

Specifies the execution priority of an event handler.

指定事件处理器的执行优先级。

Features | 主要功能:

  • Higher value = higher priority - 值越大优先级越高
  • Default priority is 0 - 默认优先级为0
  • Handlers execute in priority order - 处理器按优先级顺序执行

Usage Examples | 使用示例:

@Subscribe
@Priority(100)  // Executes first
public void validateOrder(OrderCreatedEvent event) {
    if (!isValid(event)) {
        event.cancel();  // Cancel to stop lower priority handlers
    }
}

@Subscribe
@Priority(50)   // Executes second
public void logOrder(OrderCreatedEvent event) {
    log.info("Order created: {}", event.getOrderId());
}

@Subscribe      // Default priority 0, executes last
public void processOrder(OrderCreatedEvent event) {
    orderService.process(event);
}

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
Since:
JDK 25, opencode-base-event V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    int
    The priority value (higher = earlier execution) 优先级值(越高越先执行)
  • Element Details

    • value

      int value
      The priority value (higher = earlier execution) 优先级值(越高越先执行)
      Returns:
      the priority value | 优先级值
      Default:
      0