Suppose I need to run this on shell,
$ su <user>; cp /x /y;
Is there a way to run threads with another unix开发者_运维技巧 user within the application ?
No. Java threads are at a finer level of granularity than unix processes; it's processes that have an effective user.
You might be able to Runtime.exec a sudo'd command. The exec creates a new unix process, which can use another user.
If sudo has been correctly configured (e.g. user joe can only exec program foobar using sudo) it shouldn't even be too much of a security problem provided you don't just punt credentials from the front-end in the command to execute.
精彩评论