正常应该优先使用 #supplyWithNewScope 或者 #runWithNewScope 手工使用beginScope和endScope的场景只有在: 上面两个方法当需要抛出多个正交异常时会造成不必要的try/catch代码 开始scope和结束scope不在一个代码块中 @throws IllegalStateException if try to start a new scope in an exist scope.
()
| 158 | * @throws IllegalStateException if try to start a new scope in an exist scope. |
| 159 | */ |
| 160 | @Nonnull |
| 161 | public static Scope beginScope() { |
| 162 | Scope scope = SCOPE_THREAD_LOCAL.get(); |
| 163 | if (scope != null) { |
| 164 | throw new IllegalStateException("start a scope in an exist scope."); |
| 165 | } |
| 166 | scope = new Scope(); |
| 167 | SCOPE_THREAD_LOCAL.set(scope); |
| 168 | return scope; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * @see #beginScope |