开发者

Does c# and java have the same synchronization issues/concepts?

I'm just learning Java, and I find that the Java docs/books put a strong emphasis on synchronization. I have read quite a bit of c# docs/books, and you just don't see that much emphasis on this topic.

Does c# handle locking/synchronization differently, or do things work differently as a web appli开发者_StackOverflow社区cation (application pools, iis, clr verus containers/jvm/tomcat) ?


lock and synchronized are broadly the same, although they're implemented somewhat differently - in particular, in C# lock is just syntactic sugar for calls to Monitor.Enter/Exit, whereas in Java there's no library equivalent.

C# doesn't have synchronized methods, although you can use [MethodImpl(MethodImplOptions.Synchronized)] to achieve much the same effect. (I think there are some subtle differences, but they're broadly the same.) I wouldn't suggest using this in either language, however - lock on private locks instead.

The other concurrency library support in .NET and Java is further apart - the primitives of Object.wait/notify/notifyAll and Monitor.Wait/Pulse/PulseAll are similar, but higher level support is fairly different.

The memory models are subtly different - if you're not trying to work without locking they're close enough, but correct lock-free code would be different in .NET and Java.

Not really sure how to answer your web application point...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜