Note that there are some explanatory texts on larger screens.

plurals
  1. PODifference in MultiThread aspect between Java and C/C++
    primarykey
    data
    text
    <p>I have read some tips that multithread implementation is largely depends on the target OS you are working on. And the OS finally provides the multithread capability. Such as Linux has POSIX standard implementation and windows32 has other way. </p> <p>But I want to know major different in programming language level. C seems to provide more choice for synchronization such as Mutex, read-write locks, record locking, Posix semaphores.</p> <p>But in Java, I know we can use synchronized works like Mutex? And some other high-level API like AtomicXX and volatile. But I didn't find anything like record locking and read-write locks. Is it a weak side of Java language? Or it is sacrifice for crossing platform?</p> <p>Also I want to know is this a major reason that web server like nginx and DB like oracle are all written in C/C++?</p> <p>I am actually a Java developer and I am very curious about it. Hope some one can give me some advice about it.</p> <p><strong>EDIT:</strong></p> <p>Paul and Jesper already advised that Java support all the similar lock class like C/C++ after JDK1.5. But if possible, I still wish some one can explain more details why Java provides enough support, we still cannot find a pure Java "oracle". </p> <p><strong>EDIT:</strong></p> <p>Also I want to add something interesting I learned from developer.com by Nasir Khan. <a href="http://www.developer.com/java/article/0,,12082_951051,00" rel="noreferrer">Understanding Java Multithreading and Read-Write Locks</a>.</p> <p>Some topic in it.</p> <ul> <li>The interaction of the shared main memory with the thread's local memory, </li> <li>The meaning of "synchronization" with respect to this interaction and the mutual exclusion. </li> <li>Clarify the distinction of an object's lock and the resources it guards.</li> </ul> <p><strong>EDIT:</strong></p> <p>From <a href="http://download.oracle.com/javase/1.4.2/docs/api/java/nio/channels/FileLock.html" rel="noreferrer">FileLock</a> JavaDocs</p> <blockquote> <p>File locks are held on behalf of the entire Java virtual machine. They are not suitable for controlling access to a file by multiple threads within the same virtual machine. </p> </blockquote> <p>File lock in Java is exactly as same as in C/C++.</p> <p><strong>UPDATE</strong> <br/>I find another interesting area to compare that is <br/>in C++, there is some thing like </p> <pre><code>atomic&lt;int&gt; x, y; </code></pre> <p><br/>in JAVA we also have <code>AtomicInteger</code>. Are they the same thing?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload