In Effective Java 2nd edition, item 66 "Synchronize Access to Shared mutable data" it states the following program can run forever:
but on my windows and mac machines (windows, mac), it runs as expected, stopping after a second.
on a ubuntu development server, it hangs like the author says it will.
The author says the virtual machine may transform this:
"which is precisely what the HotSpot Server VM does"
So, I thought that I could force the HotSpot server vm option with java -server StopThread, but I could not get the
program to run any differently.
my windows desktop:
Question is: How to force the HotSpot server to make my program run forever on my Windows desktop?
After more testing, it turns out that StopThread does run forever (on my desktop) if I use java -server StopThread and it stops after 1 second when I use java StopThread
and on the server it does run forever if I use java StopThread.
I think the takeaway here is that, like the author says, you can't rely on it running forever or NOT running forever.