Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upProvide more ways to run with Context #2611
Comments
|
Seems like a nice method to add, though maybe not so helpful in our codebase specifically since we would probably still generally pick the former for better performance. Want to make sure no one picks up this issue and rewrites all the current usage at the same time as adding the method :) |
Good point, we create an additional
I think we don't need to change the current usage in our code base. Let's just give more options to our users. |
|
Is the requirement just wrapping this try clause using |
|
The // 1. use makeContextAware()
// wrap the given Runnable with request context
Runnable contextAwareRunnable = ctx.makeContextAware(() -> {
logger.trace(decorate(msg));
});
...
// can execute returned Runnable with request context later
contextAwareRunnable.run();
// 2. or use push()
// immediately push current request context to context storage such as ThreadLocal
try (SafeCloseable ignored = ctx.push()) {
logger.trace(decorate(msg));
}I think we can give users another option. Runnable r = () -> {
// some logic should run with request context
}
ctx.run(r);This seems a shortcut for |
|
I am still not sure why this feature is required. This issue is for providing handy interfaces ? You said that this can be reduced additional runnable interface creation. (Maybe reusing existing runnable instance, right?) Still, I could not come up easily the situation is. |


In our codebase, we push
RequestContextand immediately run some code with try-with-resources.For example:
If
RequestContextprovidesrun(Runnable)orcall(Callable)we can reduce boilerplate code and simplify it.This is inspired by gRPC Context API.
https://grpc.github.io/grpc-java/javadoc/io/grpc/Context.html#run-java.lang.Runnable-