Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.dynjs.runtime;
 
 import java.util.List;
 
 public class ThreadContextManager {
 
     private static ThreadLocal<List<ExecutionContext>> threadContext = new ThreadLocal<>();
 
    public static ExecutionContext currentContext() {
        List<ExecutionContextcurrentList = .get();
        if (currentList == null || currentList.isEmpty()) {
            return null;
        }
        return currentList.get(0);
    }
    public static void pushContext(ExecutionContext context) {
        List<ExecutionContextcurrentList = .get();
        if (currentList == null) {
            currentList = new ArrayList<>();
            .set(currentList);
        }
        currentList.add(context);
    }
    public static void popContext() {
        List<ExecutionContextcurrentList = .get();
        if (currentList == null) {
            throw new IllegalStateException("Cannot pop ExecutionContext from empty stack");
        }
        ExecutionContext head = currentList.get(currentList.size() - 1);
        currentList.remove(currentList.size() - 1);
        if (!currentList.isEmpty()) {
            if (head.isThrowInProgress()) {
                ExecutionContext nextHead = currentList.get(currentList.size() - 1);
                nextHead.addThrowStack(head.getThrowStack());
            }
        }
        //if ( currentList.isEmpty() ) {
        //threadContext.remove();
        //}
    }
New to GrepCode? Check out our FAQ X