[PATCH] 4851444: Exposing sun.reflect.Reflection#getCallerClass as a public API in Java 8
Mandy Chung
mandy.chung at oracle.com
Sat Sep 21 00:43:55 UTC 2013
On 9/20/2013 5:25 PM, Remi Forax wrote:
> What you can do is to call a function that will take the stream as
> argument and close the stream after its use and before returning.
>
> <R> R processStackStream(Function<StackStream, R> fun) {
> StackStream stackStream = new
> StackStream(Thread.currentThread()); // bias the stack stream on the
> current thread
> // the current thread is checked before doing something on the stream.
> try {
> return fun.apply(stackStream); // the stack stream is visible
> by the user, but it can not use it in another thread
> } finally {
> stackStream.close(); // set a flag saying that you can't
> access to the underlying stack stream anymore
> // the flag doesn't need
> to be volatile if the current thread is checked first
> }
> }
Good idea. I'll explore this.
thanks
Mandy
More information about the core-libs-dev
mailing list