2

I am a java developer, I was studying Multi-threading. Correct me if I am wrong, I have understood that threads made by java/jvm are created in OS. So my question is that, is thread created with java is same as thread created in C++?

6
  • Comparison of Java and C++ Commented Nov 25, 2014 at 15:33
  • 2
    this is rather a broad question, but i hope that it'll help you: when you create an OS thread, it's the same as any other OS thread regardless of the language you wrote it in Commented Nov 25, 2014 at 15:35
  • thxn @NoIdeaForName thats what i was thinking Commented Nov 25, 2014 at 15:38
  • @NoIdeaForName if you read the link in wikipedia provided by ChrisK you will notice that there are differences despite the programming language used e.g. optimization. Commented Nov 25, 2014 at 15:44
  • 3
    Remember, a JVM is a Java Virtual Machine. It is possible for a JVM to implement threads without using native threads to do it. Some people call those simulated threads "green threads". But, any production-quality JVM will create one native thread for each Java thread. Commented Nov 25, 2014 at 15:47

1 Answer 1

2

Java threads (in the long ago) were implemented with non-native threads called Green threads.

More modern versions of Java do utilize native threads which are similar to C++ threads but are a bit more abstract. Further, there still might be a many to many relationship between Java threads and the native OS threads (see Query by Slice, Parallel Execute, and Join: A Thread Pool Pattern in Java and of course a M:N model is pretty much mandatory on Windows) in which case they are still built on native threads but they are not (necessarily) isomorphic (1:1) to native threads.

Sign up to request clarification or add additional context in comments.

1 Comment

We should probably note that "thread in C++" is more complex in the first place: the language-level multithreading support only came about in C++11, and threads were previously provided by platform-specific libraries like POSIX pthreads and Windows threads. Java = one abstraction, many implementations; C++ = many abstractions, many implementations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.