1 package org
.jetbrains
.idea
.svn
;
3 public class ReentranceDefence
{
4 protected final ThreadLocal
<Boolean
> myThreadLocal
;
6 protected ReentranceDefence() {
7 myThreadLocal
= new ThreadLocal
<Boolean
>() {
9 protected Boolean
initialValue() {
15 public static <T
> T
executeReentrant(final ReentranceDefence defence
, final MyControlled
<T
> controlled
) {
16 if (defence
.isInside()) {
17 return controlled
.executeMeSimple();
19 return controlled
.executeMe();
22 public boolean isInside() {
23 return ! Boolean
.TRUE
.equals(myThreadLocal
.get());
26 public boolean isOutside() {
30 public void executeOtherDefended(final Runnable runnable
) {
32 myThreadLocal
.set(Boolean
.FALSE
);
35 myThreadLocal
.set(Boolean
.TRUE
);
39 public interface MyControlled
<T
> {