multi threading python/ruby vs java?
i wonder if the multi threading in python/ruby is equivalent to the one in java?
by that i mean, is it as efficient?
cause if you want to create a chat application that use comet technology i know that you have to use multi threading.
does this mean th开发者_开发知识库at i can use python or ruby for that or is it better with java?
thanks
This is not a question about Ruby, Python or Java, but more about a specific implementation of Ruby, Python or Java. There are Java implementations with extremely efficient threading implementations and there are Java implementations with extremely bad threading implementations. And the same is true for Ruby and Python, and really basically any language at all.
Even languages like Erlang, where an inefficient threading implementation doesn't even make sense, sometimes have bad threading implementations.
For example, if you use JRuby or Jython, then your Ruby and Python threads are Java threads. So, they are not only as efficient as Java threads, they are exactly the same as Java threads.
Both Ruby and Python use a global interpreter lock. The issue is discussed in detail here: Does ruby have real multithreading?
philosodad is not wrong to point out the constraint that the GIL presents. I won't speak for Ruby, but I am sure that it's safe to assume that when you refer to Python that you are in fact referring to the canonical cPython implementation.
In the case of cPython, the GIL matters most if you want to parallelize computationally intensive operations implemented in Python (as in not in C extensions where the GIL can be released).
However, when you are writing a non-intensive I/O-bound application such as a chat program, the efficiency of the threading implementation really just doesn't matter all that much.
精彩评论