I´m looking for best practices and I´m applying PMD to my Java EE Project, but one rule says that I have to avoid using java.lang.ThreadGroup, and I´m using it right now.
The rule says that is not safe, and I want to know: Why? Thanks
I´m looking for best practices and I´m applying PMD to my Java EE Project, but one rule says that I have to avoid using java.lang.ThreadGroup, and I´m using it right now.
The rule says that is not safe, and I want to know: Why? Thanks
Copyright © 2021 Jogjafile Inc.
The concept of using ThreadGroup for security reasons has been abandoned as there is no controllable relationship between a Thread(Group) and the actual code it is executing. Even the most privileged thread could run insecure code and thus elevate that code to an undesired level. Therefore the code being executed itself (and its origin) is used for deciding which permission it has. So the executing thread and its group does not play any role to security in any way.
So after that,
ThreadGroupoffers no real functionality. It just became obsolete, only maintained for historical reasons. The only functionality which did not work without wasuncaughtException(Thread t, Throwable e). But since Java 5 there isThread.setUncaughtExceptionHandler( UncaughtExceptionHandler)so now even that works without thread groups.Yes, a lot of
ThreadGroups methods are not thread-safe and there was no attempt to fix them, just because they’re obsolete anyway.Joshua Bloch writes in “Effective Java”: