差异在Java和C / C之间多线程方面++ [英] Difference in MultiThread aspect between Java and C/C++

查看:198
本文介绍了差异在Java和C / C之间多线程方面++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过一些技巧,多线程的实现在很大程度上取决于你的工作目标操作系统。和OS最后提供多线程功能。如Linux有POSIX标准的实施和WINDOWS32有其他方式。

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.

但我想知道的编程语言水平的主要不同。 ç似乎同步,如互斥提供更多选择,读写锁,记录锁,POSIX信号量。

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.

但在Java中,我知道我们可以用作品同步互斥样?和其他一些高级API类似AtomicXX震荡。但我没有找到像记录锁定任何东西,读写锁。它是Java语言的一个软弱的一面?或者是牺牲跨平台?

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?

此外,我想知道这是一个主要的原因是Web服务器一样nginx的和DB,如Oracle都用C / C ++?

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++?

我其实是一个Java开发人员,我很好奇。
希望有人可以给我一些建议吧。

I am actually a Java developer and I am very curious about it. Hope some one can give me some advice about it.

编辑:

保罗和加斯帕已经劝了Java支持所有类似的锁类像JDK1.5后,C / C ++。但是,如果可能的话,我仍然希望有人能解释更多的细节,为什么Java提供了足够的支持,我们仍然不能找到一个纯Java甲骨文。

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".

编辑:

此外,我想添加一些有趣的事情,我从developer.com由纳西尔·汗的教训。
了解Java多线程和读写锁

Also I want to add something interesting I learned from developer.com by Nasir Khan. Understanding Java Multithreading and Read-Write Locks.

一些话题吧。


  • 共享的主的相互作用
    内存与线程的地方
    内存

  • 同步的含义
    相对于这种相互作用
    和互斥。

  • 明确的区别
    对象的锁,它保护的资源。

编辑:

的FileLock 的JavaDoc

文件锁定持有代表整个Java虚拟机。它们不适合用于控制同一虚拟机内访问文件由多个线程。

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.

在Java文件锁正是在C / C ++相同。

File lock in Java is exactly as same as in C/C++.

更新

我找到另外一个有趣的领域来比较是

在C ++中,有一些东西像

UPDATE
I find another interesting area to compare that is
in C++, there is some thing like

atomic<int> x, y;


JAVA我们也有的AtomicInteger
他们是同样的事情?


in JAVA we also have AtomicInteger. Are they the same thing?

推荐答案

Java并提供读写锁 - 的http://download.oracle.com/javase/6/docs/api/java/util/concurrent/locks/ReadWriteLock.html.

Java does provide read-write locks - http://download.oracle.com/javase/6/docs/api/java/util/concurrent/locks/ReadWriteLock.html.

看一看java.util.concurrent包,如果你还没有。我怀疑Java的支持,足以媲美C中的。此外,还有一些用Java编写的Web服务器使用的任何多线程或异步IO(NIO)。

Have a look at the java.util.concurrent package if you haven't already. I suspect Java's support is comparable to C's. There are also a number of web servers written in Java that use either multithreaded or async IO (NIO).

这篇关于差异在Java和C / C之间多线程方面++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆