when I was in college my OO design and programming professor always made reference that Java threads are evil.
Originally posted by Didier VAron:
I don't know if this question has already posted, but when I was in college my OO design and programming professor always made reference that Java threads are evil.
Cheers!<br /><b>Annie</b>
Originally posted by Annie Smith:
Sounds similar to one of my professors who said pointers are a horror in C. I almost always disagreed with him.
Originally posted by Warren Dew:
I've worked with multithreaded code quite a bit, and I think I understand what the professor meant.
In general, Java is a very "safe" language: singly threaded code has few or no dependencies on the environment in which it is run. Indeed, much of the point of Java was to provide a language that was 'write once, run anywhere'. This greatly simplifies testing and debugging, since you don't have to worry about testing on every single possible platform, and you don't have to duplicate a user's exact setup to duplicate his bugs.
Unfortunately, Java threads do not have such guarantees. The behavior of threads in Java is highly platform dependent, and code that always works perfectly on one machine may fail in unexplained ways on a different machine or operating system. In particular, the memory model, which does not require cache coherency, allows almost anything to happen if you aren't extremely careful - and those problems are nearly impossible to test for, since many of the problems that could come up on some platforms, such as those without cache coherency, cannot come up on many development platforms.
I think the simile to C pointers is an apt one. To the extent that the primary benefit of Java is to remove "evil" undefined behavior such as that associated with wild pointers in C, Java threads are "evil". Sometimes they are a necessary evil, though.
Originally posted by praveen k:
im not a great expert in java.i have used threads in one of my project.i dont find any problems although its cautioned that you cannot rely it for a critical problem.i believe it all depends on how one uses it.If it is an evil thing then why sun would have included this feature.its only an warning thats all and we should consider it.