• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TAKETODAY / today-infrastructure / 18154768944

01 Oct 2025 07:26AM UTC coverage: 81.882% (-0.005%) from 81.887%
18154768944

push

github

web-flow
Merge pull request #290 from TAKETODAY/dev/jspecify

jspecify

59788 of 78013 branches covered (76.64%)

Branch coverage included in aggregate %.

141239 of 167496 relevant lines covered (84.32%)

3.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.19
today-context/src/main/java/infra/scheduling/support/ScheduledMethodRunnable.java
1
/*
2
 * Copyright 2017 - 2025 the original author or authors.
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see [https://www.gnu.org/licenses/]
16
 */
17

18
package infra.scheduling.support;
19

20
import org.jspecify.annotations.Nullable;
21

22
import java.lang.reflect.InvocationTargetException;
23
import java.lang.reflect.Method;
24
import java.lang.reflect.UndeclaredThrowableException;
25

26
import infra.scheduling.SchedulingAwareRunnable;
27
import infra.scheduling.annotation.ScheduledAnnotationBeanPostProcessor;
28
import infra.util.ReflectionUtils;
29

30
/**
31
 * Variant of {@link MethodInvokingRunnable} meant to be used for processing
32
 * of no-arg scheduled methods. Propagates user exceptions to the caller,
33
 * assuming that an error strategy for Runnables is in place.
34
 *
35
 * @author Juergen Hoeller
36
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
37
 * @see ScheduledAnnotationBeanPostProcessor
38
 * @since 4.0
39
 */
40
public class ScheduledMethodRunnable implements SchedulingAwareRunnable {
41

42
  private final Object target;
43

44
  private final Method method;
45

46
  @Nullable
47
  private final String qualifier;
48

49
  /**
50
   * Create a {@code ScheduledMethodRunnable} for the given target instance,
51
   * calling the specified method.
52
   *
53
   * @param target the target instance to call the method on
54
   * @param method the target method to call
55
   * @param qualifier a qualifier associated with this Runnable,
56
   * e.g. for determining a scheduler to run this scheduled method on
57
   */
58
  public ScheduledMethodRunnable(Object target, Method method, @Nullable String qualifier) {
2✔
59
    this.target = target;
3✔
60
    this.method = method;
3✔
61
    this.qualifier = qualifier;
3✔
62
  }
1✔
63

64
  /**
65
   * Create a {@code ScheduledMethodRunnable} for the given target instance,
66
   * calling the specified method.
67
   *
68
   * @param target the target instance to call the method on
69
   * @param method the target method to call
70
   */
71
  public ScheduledMethodRunnable(Object target, Method method) {
72
    this(target, method, null);
5✔
73
  }
1✔
74

75
  /**
76
   * Create a {@code ScheduledMethodRunnable} for the given target instance,
77
   * calling the specified method by name.
78
   *
79
   * @param target the target instance to call the method on
80
   * @param methodName the name of the target method
81
   * @throws NoSuchMethodException if the specified method does not exist
82
   */
83
  public ScheduledMethodRunnable(Object target, String methodName) throws NoSuchMethodException {
84
    this(target, target.getClass().getMethod(methodName));
9✔
85
  }
1✔
86

87
  /**
88
   * Return the target instance to call the method on.
89
   */
90
  public Object getTarget() {
91
    return this.target;
3✔
92
  }
93

94
  /**
95
   * Return the target method to call.
96
   */
97
  public Method getMethod() {
98
    return this.method;
3✔
99
  }
100

101
  @Override
102
  @Nullable
103
  public String getQualifier() {
104
    return this.qualifier;
3✔
105
  }
106

107
  @Override
108
  public void run() {
109
    try {
110
      ReflectionUtils.makeAccessible(this.method);
4✔
111
      this.method.invoke(this.target);
8✔
112
    }
113
    catch (InvocationTargetException ex) {
×
114
      ReflectionUtils.rethrowRuntimeException(ex.getTargetException());
×
115
    }
116
    catch (IllegalAccessException ex) {
×
117
      throw new UndeclaredThrowableException(ex);
×
118
    }
1✔
119
  }
1✔
120

121
  @Override
122
  public String toString() {
123
    return this.method.getDeclaringClass().getName() + "." + this.method.getName();
×
124
  }
125

126
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc