@Test public void testExplicitThreadCannotAndUseSubjectFromMainThread() throws InterruptedException { final AtomicReference<List<String>> inputReference = new AtomicReference<List<String>>(null); final AtomicBoolean outputReference = new AtomicBoolean(false); Thread childThread = new Thread(() -> { outputReference.set(true); List<String> subjectInChildThread = inputReference.get(); subjectInChildThread.add(testString); outputReference.set(false); }); @SuppressWarnings("unchecked") List<String> subject = ThreadConfinedProxy.newProxyInstance(List.class, new ArrayList<String>(), ThreadConfinedProxy.Strictness.VALIDATE); inputReference.set(subject); childThread.start(); childThread.join(10000); assertTrue(outputReference.get()); }
public static <T> T newProxyInstance(Class<T> interfaceClass, T delegate, Strictness strictness) { return newProxyInstance(interfaceClass, delegate, strictness, Thread.currentThread()); }
ThreadConfinedProxy extends AbstractInvocationHandler implements DelegatingInvocationHandler { public static <T> T newProxyInstance(Class<T> interfaceClass, T delegate, Strictness strictness) { return newProxyInstance(interfaceClass, delegate, strictness, Thread.currentThread()); } }
ThreadConfinedProxy extends AbstractInvocationHandler implements DelegatingInvocationHandler { public static <T> T newProxyInstance(Class<T> interfaceClass, T delegate, Strictness strictness) { return newProxyInstance(interfaceClass, delegate, strictness, Thread.currentThread()); } private  ThreadConfinedProxy(Object delegate, Strictness strictness, String threadName, long threadId); }
ThreadConfinedProxy extends AbstractInvocationHandler implements DelegatingInvocationHandler { public static <T> T newProxyInstance(Class<T> interfaceClass, T delegate, Strictness strictness) { return newProxyInstance(interfaceClass, delegate, strictness, Thread.currentThread()); } private  ThreadConfinedProxy(Object delegate, Strictness strictness, String threadName, long threadId); static T newProxyInstance(Class<T> interfaceClass, T delegate, Strictness strictness); static void changeThread(Object proxy, Thread oldThread, Thread newThread); static Callable<T> threadLendingCallable(final Object proxy, final Callable<T> callable); @SuppressWarnings("unchecked") static T newProxyInstance(Class<T> interfaceClass, T delegate, Strictness strictness, Thread current); @Override Object getDelegate(); }
ThreadConfinedProxy extends AbstractInvocationHandler implements DelegatingInvocationHandler { public static <T> T newProxyInstance(Class<T> interfaceClass, T delegate, Strictness strictness) { return newProxyInstance(interfaceClass, delegate, strictness, Thread.currentThread()); } private  ThreadConfinedProxy(Object delegate, Strictness strictness, String threadName, long threadId); static T newProxyInstance(Class<T> interfaceClass, T delegate, Strictness strictness); static void changeThread(Object proxy, Thread oldThread, Thread newThread); static Callable<T> threadLendingCallable(final Object proxy, final Callable<T> callable); @SuppressWarnings("unchecked") static T newProxyInstance(Class<T> interfaceClass, T delegate, Strictness strictness, Thread current); @Override Object getDelegate();  }