szetszwo commented on PR #7892:
URL: https://github.com/apache/hadoop/pull/7892#issuecomment-3250102379
@stoty , thanks for trying it out! The code should look like below:
```java
public class SubjectDoAsThread extends Thread {
private final Runnable runnable;
private Subject startSubject;
public static class Builder {
private ThreadGroup group;
private String name;
private Runnable runnable;
public Builder setThread(Thread thread) {
this.group = thread.getThreadGroup();
this.name = thread.getName();
this.runnable = thread;
return this;
}
public SubjectDoAsThread build() {
return new SubjectDoAsThread(group, name, runnable);
}
}
private SubjectDoAsThread(ThreadGroup group, String name, Runnable
runnable) {
super(group, name);
this.runnable = Objects.requireNonNull(runnable, "runnable == null");
}
@Override
public final void start() {
startSubject = SubjectUtil.current();
super.start();
}
@Override
public final void run() {
SubjectUtil.doAs(startSubject, (PrivilegedAction<Void>) () -> {
runnable.run();
return null;
});
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]