- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
There is a "not" missing in "webserver shutting down properly".
Admin
Disagree : there is a probability that the designers of the code [a third party] did not consider the use case required. Of course the is the possibility to not use that package and find a different offering or roll your own (perhaps 10's of thousands of lines). If the code does indeed deadlock, and there is not a valid (documented, supported b the vendor) means of addressing the issue, this is perfectly valid EXCEPT the "voodoo comment" - instead there should be proper explanation of why this was necessary
Admin
"my name (unregistered)" -- How would a kill 9 on a PROCESS, allow the PROCESS to properly run while shutting down ONE SPECIFIC thread...???
Admin
I am not sure in which version Java closed this nasty holes in the language, but this no longer works in Java 17. In Java 8, it prints "One=2".
Addendum 2024-07-25 11:27: The real WTF was setAccessible.
Admin
Exatly! That's why we don't upgrade Java anymore. Too dangerous.
-- Jaco's CTO, probably.
Admin
The comment above the "voodoo"-one explains the necessity: The regular way shutting down the WebServer leads to a deadlock. This looks like some third-party library where you need to wait for a fix from the provider, but until then you need to find a way to shut down the (supposedly) non-daemon-threads of that web server that prevent your own application to shut down properly: A java process doesn't exit unless all non-daemon-threads are terminated.
BTDT myself and you can be sure that the one who did it, felt bad while doing it. But there are occasions where this simply is necessary. Another example was doing SSL Session resumption on an FTP data-connection with the standard TLS library that comes with the JVM. Simply put: You can't but if you need to, you need your Reflection-Voodoo ready: https://eng.wealthfront.com/2016/06/10/c/
Admin
Maybe. Maybe not. According to the Java docs the thread needs to support interruption. i.e. it needs to call a method that can throw
InterruptedException
or periodically inspect itsinterrupted()
property. More insidiously, the writer might have decided to catchInterruptedException
, swallow it and then carry on.Admin
Only problem is that interrupts in java are handled by throwing an exception. An exception that can be caught, especially in calls to external services, say, a database with a third party library like, say, Spring/JDBC. Ask me how I know.
Also, I love reflection. Didn't get to use it much, and mostly used it for configuration/set-up stuff outside of weird investigative one-offs, but always a blast.
Admin
Only problem is that interrupts in java are handled by throwing an exception. An exception that can be caught, especially in calls to external services, say, a database with a third party library like, say, Spring/JDBC. Ask me how I know.
Also, I love reflection. Didn't get to use it much, and mostly used it for configuration/set-up stuff outside of weird investigative one-offs, but always a blast.
Admin
The "helpful tip" implies that all code beyond our control is written the way it should. In other words, we are in paradise, and I want my nectar and ambrosia.
Admin
he wants to shutdown the webserver, so I buttumed the webserver would run in its own process
Admin
If you haven't had to use reflection to get access to some private method or variable, then you haven't done any real programming.
Admin
If it's your own code, sure, this is a WTF. But it sounds like this is a 3rd-party component that doesn't follow "best-coding practice". In that situation, sure, I'd do this too.
The real WTF here is somehow assuming that this wasn't necessary when the comment itself shows that trying to do it the "sane" way results in a deadlock. And from the deliberate way it's been done, it looks like someone decompiled the code, carefully checked what could be done to make the component shutdown sanely, and did that.
I don't even agree with commenters on this thread saying "explain why this works"… let's see, you set the "listener" field to null on a network service. It's quite self explanatory. If you don't know why that might work to gum up the works, maybe you've never done anything with networks… and in that case, what's the point of explaining with a paragraph of comments?
Admin
Depends on a lot of things, 'kill -9' isn't the first thing you should reach for.
The database we use at work runs in 'Shared Memory', this makes it extremely quick, since it doesn't have to rely on sockets, etc... The system built on top of it runs in shared memory mode to talk to the database.
If the code gets stuck, going straight to 'kill -9' means the database goes down too.
One should always go up the kill stack, start off kind and get more aggressive as you go along.